JSF 2 composite component, passing attributes to backing bean
Asked Answered
A

1

1

I'm stuck on simple JSF2 question:

XHTML:

<xvf:simpleOut identifier="12345"/>

Composite component is supposed to pass "12345" to backing bean and do some output:

<composite:interface>
    <composite:attribute name="identifier" required="true" type="java.lang.String"/>
</composite:interface>

<composite:implementation>
    <!--@elvariable id="arg" type="java.lang.String"-->
    <ui:param name="arg" value="#{cc.attrs.identifier}"/>
    <h:outputText value="#{myBean.getTestOutput('???????')}"/>
</composite:implementation>

How do I pass identifier value, '12345' in my case, to bean's getTestOutput(String arg) method?

Abercromby answered 28/3, 2011 at 14:34 Comment(0)
C
4

You don't need the <ui:param> tag at all. This should work:

<h:outputText value="#{myBean.getTestOutput(cc.attrs.identifier)}"/>

But it might a a good idea to pass myBean through the interface as well rather than refering to it directly, since it would make the composite component reusable.

Cabral answered 28/3, 2011 at 16:9 Comment(3)
Thanks, you've saved my day! It's new to me that cc.attrs.*, unlike elvariables, can be passed to backing beans.Abercromby
@Osw: I'm not sure what you mean by "unlike elvariables". If a variable can be resolved by an EL Resolver, it can be passed to a method - if your JSF container supports method parameters in EL expression, which is only available in EL 2.2.Cabral
you're right. My fault is that I've used nested el expressions like '#{myBean.getTestOutput(#{arg})}'. Thanks again.Abercromby

© 2022 - 2024 — McMap. All rights reserved.