How to get the ui:param value in Javabean
I am learning facelets and Seam and I'm facing the following problem: I have 2 xhtml files, one includes the other and each one has its own Seam component as backing bean. I want to send and object to the included facelet and obtain that object in the backing bean corresponding to the included facelet. I'll take an example to explain better the situation:
- registration.xhtml with S开发者_StackOverflow社区eam component as backing bean Registration.java. In this class I have an object of type Person
- address.html with Seam component as backing bean Address.java. In this class i want to obtain the Person object from the Registration component and set the address.
- registration.xhtml includes the address.xhtml and passes an object using
How to obtain this object in Address bean? Will be the same reference of the object from the Registration bean? ui:param is the solution of passing this object or there is another solution for that? (maybe f:attribute, but even in this case how do I obtain the object in bean)
This example is simple and not necessarily realistic but I have a similar problem and I don't know how to solve it.
Thanks in advance.
You could use a Page action to wire your bean
<page view-id="/registration.xhtml">
<action execute="#{registrationBackingBean.wire}"/>
</page>
...
@Name("registrationBackingBean")
public class RegistrationBackingBean {
@In(required=false)
private Person person;
@In(required=false)
private Address address;
public void wire() {
person.setAddress(address);
}
}
If you want to wire during an initial request (GET), do as follows
<page view-id="/registration.xhtml">
<action execute="#{registrationBackingBean.wire}" if="#{empty param['javax.faces.ViewState']}"/>
</page>
精彩评论