JSF 2 - passing parameters accross system events
I have a composite component, where I pass in an arbitrary defined attribute:
<x:mycomp x="..."/>
x
being defined as such in the interface definition of the cc. Inside the i开发者_如何转开发mplementation of mycomp
I have an event listener:
<composite:implementation>
<f:event type="preRenderComponent" listener="#{mycontroller.init}" />
</composite:implementation>
Now I would like to do something on the backend with this arbitary parameter x
. how do I pass it accross the system event, like with an f:attribute
tag? or getting the source component from the event and trawling through its internals? (speaking of which where in the UIComponent are these attributes stored anyway - I couldn't find them, not in attributes anyway).
If not possible this severely limits the usefulness of system events. If you put the component inside a ui:repeat
the listener is fired multiple times so it is walking through the tree during event firing.
Only thing I can think of is to encode the init directly into the render:
<composite:implementation>
#{mycontroller.init(cc.attrs.x)} //returns empty string
<!--f:event type="preRenderComponent" listener="#{mycontroller.init}" /-->
</composite:implementation>
But I thought thats what a prerender system event would be for.
Maybe it's a little late for the answer.
I made a proof of concept of what I think is the problem that you are trying to resolve. In order to make it, you have to take out your event registration and doing it in the using page of your composite. Your init method can receive a ComponentSystemEvent that will give you the composite component and then you could access your 'x' attribute from the map of attributes of the component.
The code in the using page is something like this:
<x:mycomp x="hola">
<f:event type="preRenderComponent" listener="#{bean.init}"/>
</x:mycomp>
And the java code:
public class MyBean {
private String value;
public void init(ComponentSystemEvent e){
System.out.println("x: "+e.getComponent().getAttributes().get("x"));
}
}
I hope it will be useful (some months later).
精彩评论