Is it possible to reuse one page multiple times attached to different objects?
I have a page were you can input personal information (name, address, social number, ...) connect to one bean: prospect. In some occasions I must gather linked personal information. example for credit scoring (a person and a guarantor).
So I wanted to use with 2 includes. But how can I make sure include1 holds the information for person1 and include2 holds the information for person2?
<rich:tabPanel id="creditScoreTab" switchType="client" >
<rich:tab id="mainContractor" >
<ui:include src="includes/prospect.xhtml" />
</rich:tab>
<rich:tab id="guarantor">
<ui:include src="includes/prospect.xhtml" />
</rich:tab>
</rich:tabPanel>
and facescontext
<managed-bean>
<managed-bean-name>prospect</managed-bean-name>
<managed-bean-class>be.foo.Prospect</managed-bean-class>
<managed-bean-scope>view</managed-bean-scope>
</managed-bean>
I found 2 possible work arounds: -duplicate the page and define 2 beans in faces-config (pointing to the same java class) -do not use tabpanel and include, but enter person1 info , then save it and load person2 info and save person2.
Workaround1 negative point is that it is maintaining the same code twice. Workaround2 negative point is that it is not so 'cool' (ux point of view)
You can use <ui:param>
to pass parameters to <ui:include>
:
<rich:tabPanel id="creditScoreTab" switchType="client" >
<rich:tab id="mainContractor" >
<f:subview id="mainContractorView">
<ui:include src="includes/prospect.xhtml">
<ui:param name="person" value="#{bean.person1}" />
</ui:include>
</f:subview>
</rich:tab>
<rich:tab id="guarantor">
<f:subview id="guarantorView">
<ui:include src="includes/prospect.xhtml">
<ui:param name="person" value="#{bean.person2}" />
</ui:include>
</f:subview>
</rich:tab>
</rich:tabPanel>
With the above example, in each include the desired person will be available as #{person}
. Those <f:subview>
tags are to prevent duplicate component ID errors because they end up within the same UINamingContainer
parent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With