You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JSF中cc.attributes与cc.attrs语法来源及相关内容咨询

Understanding #{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.

  • Composite component implicit objects: Besides cc.attributes/cc.attrs, the cc object gives you access to other useful properties:
    • cc.parent: The parent component that contains your composite component
    • cc.resource: Access to resources (like CSS/JS files) linked to the composite component
    • cc.clientId: The full client-side ID of the composite component, handy for JavaScript interactions
  • cc.attributes as a Map: Under the hood, cc.attributes is a Map<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.attributes and cc.attrs are standardized means you can trust their usage across different JSF implementations.

内容的提问来源于stack exchange,提问作者GarfieldKlon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:19:02