JSF中cc.attributes与cc.attrs语法来源及相关内容咨询
#{cc.attributes} in JSF Composite Components Hey there! Let's clear up the confusion around cc.attributes and related JSF composite component syntax—this is a common point of confusion for beginners, so you're not alone.
First, what's cc?
The cc in #{cc.attributes} is an implicit EL object tied to the composite component namespace xmlns:cc="http://xmlns.jcp.org/jsf/composite". It represents the current instance of your composite component, giving you direct access to its properties, parent components, and resources in EL expressions.
cc.attributes vs cc.attrs—they're identical!
You mentioned finding more info about cc.attrs but not cc.attributes—that's because cc.attrs is just a shorthand alias for cc.attributes. The JSF specification defines both as valid ways to access the map of attributes passed to the composite component.
Most tutorials and examples lean on cc.attrs because it's shorter, but both work exactly the same. So #{cc.attributes.value} is no different from #{cc.attrs.value}—use whichever feels more readable to you.
What your code is doing
Let's break down your specific line:
<ui:param name="notes" value="#{cc.attributes.value}"></ui:param>
This creates a local EL variable named notes that references the value attribute passed to your composite component. For example, if you use your composite component in a parent page like this:
<my:customComponent value="Some important notes" />
Then #{notes} in your composite component's view will resolve to "Some important notes". It's just a way to create a more concise variable name instead of typing #{cc.attributes.value} everywhere.
Related key concepts to explore
- Composite component implicit objects: Besides
cc.attributes/cc.attrs, theccobject gives you access to other useful properties:cc.parent: The parent component that contains your composite componentcc.resource: Access to resources (like CSS/JS files) linked to the composite componentcc.clientId: The full client-side ID of the composite component, handy for JavaScript interactions
cc.attributesas a Map: Under the hood,cc.attributesis aMap<String, Object>that stores all attributes passed to the composite component. You can even iterate over it (e.g., with<ui:repeat>) to handle dynamic attributes.- JSF spec background: The JSF specification (specifically the composite components chapter) formally defines all these implicit objects and their aliases. Knowing both
cc.attributesandcc.attrsare standardized means you can trust their usage across different JSF implementations.
内容的提问来源于stack exchange,提问作者GarfieldKlon

