【问题标题】:Reuse some .xhtml pages on a JSF primefaces application在 JSF primefaces 应用程序上重用一些 .xhtml 页面
【发布时间】:2015-07-07 17:44:33
【问题描述】:

我使用 JSF 和 PrimeFaces 开发了一个简单的应用程序,这是我面临的一个问题:

这些是具有Person 属性的托管bean:

  • ClientBean
  • EmployeeBean

我有person.xhtml,它显示了一个人的数据。我将person.xhtml 包含在client.xhtmlemployee.xhtml 上。我需要创建两个person.xhtml,因为我使用不同的bean。我想做的是这样的:

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

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

在我的person.xhtml 中,我可以使用#{person.name}#{person.dateOfBirth}。 我在JSF中搜索并使用&lt;c:set/&gt;是错误的。

有人可以帮忙吗?

【问题讨论】:

  • @Nambari 是的。我使用模板来构建页面。我需要的是如何从不同的bean中获取数据并在同一个.xhtml页面中使用。

标签: jsf facelets


【解决方案1】:

将其传递为&lt;ui:param&gt;

<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>

如有必要,将person.xhtml注册为标签文件以使其看起来更好,另请参阅When to use <ui:include>, tag files, composite components and/or custom components?

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

注意重复的组件 ID 错误。另见Avoiding duplicate ids when reusing facelets compositions in the same naming container

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-21
    • 1970-01-01
    • 2015-11-25
    • 1970-01-01
    • 2012-04-04
    • 1970-01-01
    • 2010-12-31
    • 1970-01-01
    相关资源
    最近更新 更多