gpt4 book ai didi

jsf - 在 JSF primefaces 应用程序上重用一些 .xhtml 页面

转载 作者:行者123 更新时间:2023-12-01 12:33:41 25 4
gpt4 key购买 nike

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

这些是具有 Person 的托管 bean。属性(property):

  • ClientBean
  • EmployeeBean

  • 我有 person.xhtml显示来自一个人的数据。我包括 person.xhtmlclient.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} .
    我搜索并使用 <c:set/>在 JSF 中是错误的。

    任何人都可以帮忙吗?

    最佳答案

    将其传递为 <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>

    注册 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 .

    关于jsf - 在 JSF primefaces 应用程序上重用一些 .xhtml 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31275769/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com