jsf difference between implicit objects cc and component

隐身守侯 提交于 2019-12-21 19:53:09

问题


Maybe this is a dumb question, but I use

cc

to refer to the composite component, for instance cc.attrs.randomAttr but I have also seen the

component

implicit object and I have used it because I was told to but I don't really understand what it is for. Can anyone explain please?


回答1:


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.



来源:https://stackoverflow.com/questions/5124961/jsf-difference-between-implicit-objects-cc-and-component

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