jsf difference between implicit objects cc and component

此生再无相见时 提交于 2019-12-04 12:14:02

cc refers to the top level composite component that is being processed at the time of evaluation.

component simply is the ui component being processed.

So when inside a composite component, cc refers to the 'parent' component, while component when used on an individual component refers to that particular instance. Or for simple cases:

cc == component.getCompositeComponentParent(component), with component being a component of which the composite component is build.

E.g. consider the following composite component:

<html 
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"    
    xmlns:cc="http://java.sun.com/jsf/composite"
>
    <cc:interface/>

    <cc:implementation>

        <h:outputText value="Own ID: #{component.id}, parent composite ID: #{cc.id}" /> <br/>
        <h:outputText value="Own ID: #{component.id}, parent composite ID: #{cc.id}" />

    </cc:implementation>    

</html>

Using this on a Facelet will print 2 different "own" IDs, namely the ones of the two outputText components, while the composite ID will be the same on both lines.

Note that things may become a little more complicated when multiple nestings of composite components are involved.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!