Set Managed Bean as parameter in Composite Component
Asked Answered
S

1

5

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

Showy answered 17/11, 2011 at 0:16 Comment(2)
This makes no sense. What exactly is the functional requirement? Restricting the managed bean type to a certain type?Bishopric
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. It's not essential, i was just wondering if it's possible.Showy
B
11

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}" />
Bishopric answered 19/11, 2011 at 0:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.