Umang Mehta
Umang Mehta

Reputation: 1507

Pass a parameter inside <f:event listener="#{myBean.retrieveData(#{})">

I need to populate one datatable using database dynamically in which i need to call a retieveData() method and pass a id to criteria my result inside the method. The parameter that is to be passed is coming from another bean by #{anotherBean.id}. My question is how to pass this parameter inside the method...? Following is what i am trying to do...

<f:metadata>
     <f:event listener="#{myBean.retrieveData(#{anotherBean.id)}" type="preRenderComponent" id="fevent"/>
</f:metadata> 

Upvotes: 3

Views: 9168

Answers (2)

anandapriyo
anandapriyo

Reputation: 86

You can pass it through attribute.

Here is what I do on JSF:

<f:metadata>
    <f:event listener="#{myBean.retrieveData}" type="preRenderView" id="fevent"/>
    <f:attribute name="myid" value="#{anotherBean.id)" />
</f:metadata>

Meanwhile the managed bean (myBean) is as follow:

public void retrieveData(ComponentSystemEvent event) {
    String id = (String) event.getComponent().getAttributes().get("myid");
}

Make sure not to use '()' when calling the managed bean's method on listener of f:event tag.

Upvotes: 7

mrembisz
mrembisz

Reputation: 12880

Basically

<f:metadata>
     <f:event listener="#{myBean.retrieveData(anotherBean.id)}" type="preRenderComponent" id="fevent"/>
</f:metadata>

should do. But why don't you inject anotherBean into myBean and retrieve id in your Java code? It is usually better to keep this kind of logic in your Java code rather than view - xhtml file in this case.

Upvotes: 3

Related Questions