Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jsf difference between implicit objects cc and component

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?

like image 419
arg20 Avatar asked Jun 21 '26 12:06

arg20


1 Answers

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.

like image 86
Arjan Tijms Avatar answered Jun 23 '26 01:06

Arjan Tijms



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!