4

I developing a simple application using JSF and PrimeFaces and here's a problem that I'm facing:

These are managed beans that have a Person property:

  • ClientBean
  • EmployeeBean

I have the person.xhtml that shows the data from a person. I include the person.xhtml on a client.xhtml and employee.xhtml. I need to create two person.xhtml because I'm using different beans. What I want to do is something like that:

<c:set var="person" value="clientBean.person" /> 
<ui:include src="person.xhtml"/>

<c:set var="person" value="employeeBean.person" /> 
<ui:include src="person.xhtml"/>

And in my person.xhtml I can use #{person.name} , #{person.dateOfBirth}. I searched and use <c:set/> in JSF is wrong.

Anyone can help?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
AndreDuarte
  • 784
  • 1
  • 5
  • 21
  • @Nambari yes. I use templates to construct the pages. What I need is how to get data from different beans and use in the same .xhtml page. – AndreDuarte Jul 07 '15 at 17:51

1 Answers1

5

Pass it as <ui:param>.

<ui:include src="person.xhtml">
    <ui:param name="person" value="#{clientBean.person}" /> 
</ui:include>
<ui:include src="person.xhtml">
    <ui:param name="person" value="#{employeeBean.person}" /> 
</ui:include>

Register person.xhtml if necessary as a tag file to make it look better, see also When to use <ui:include>, tag files, composite components and/or custom components?

<my:personForm value="#{clientBean.person}" /> 
<my:personForm value="#{employeeBean.person}" /> 

Beware of duplicate component ID errors. See also Avoiding duplicate ids when reusing facelets compositions in the same naming container.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555