Reuse some .xhtml pages on a JSF primefaces application

好久不见. 提交于 2019-12-05 02:24:13

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/31275769/reuse-some-xhtml-pages-on-a-jsf-primefaces-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!