Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Managed Bean as parameter in Composite Component

Is there a way of setting a managed bean parameter in a composite component and then leaving the using classes to decide which actual managed bean to use?

something along the lines of: comp.xhtml

       <cc:interface>
            <cc:attribute name="price" />
            <cc:param name="pageBean" value="#{superBean}" />       
       <cc:interface>
       <cc:implementation>
                <h:outputText value="#{cc.attrs.price}"/>
       </cc:implementation>

And then, in the using page

   <ezcomp:comp pageBean="actualBean"
                          price="#{actualBean.price}" >

    </ezcomp:comp> 

In my case ActualBean is a subtype of SuperBean.

I'm not even sure this is possible, but let's just say it would be great if someone proved me wrong.

Thank you in advance

like image 995
glasspill Avatar asked Nov 17 '11 00:11

glasspill


1 Answers

To remove duplicate code, basically. i have a lot of attributes that need to be set in the composite component. The only thing that differs in the using pages is the name of the managed beans, all being subtypes of a superbean.

You don't need to specify all the attributes. Just specifying alone the bean is sufficient. You could reference its properties in the composite component directly.

<cc:interface>
    <cc:attribute name="pageBean" type="com.example.SuperBean" required="true" />       
<cc:interface>
<cc:implementation>
    <h:outputText value="#{cc.attrs.pageBean.price}"/>
</cc:implementation>

with

<ezcomp:comp pageBean="#{actualBean}" />
like image 118
BalusC Avatar answered Sep 28 '22 07:09

BalusC