多次重复使用同一页面

2024-03-28

是否可以多次重用一页附加到不同的对象?

我有一个页面,您可以输入个人信息(姓名、地址、社交号码……)连接到一个 bean:潜在客户。 在某些情况下,我必须收集链接的个人信息。信用评分示例(个人和担保人)。

所以我想与 2 个包含一起使用。但是我如何确保 include1 包含 person1 的信息,而 include2 包含 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>

和面孔上下文

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

我发现了两种可能的解决方法: -复制页面并在faces-config中定义2个bean(指向同一个java类) -不要使用 tabpanel 和 include,而是输入 person1 info ,然后保存并加载 person2 信息并保存 person2。

解决方法 1 的缺点是它两次维护相同的代码。解决方法 2 的缺点是它不是那么“酷”(从用户体验的角度来看)


您可以使用<ui:param> http://download.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/ui/param.html将参数传递给<ui:include> http://download.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/ui/include.html:

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

对于上面的示例,在每个包含中,所需的人员将作为#{person}. Those <f:subview>标签是为了防止重复的组件 ID 错误,因为它们最终会出现在同一个组件中UINamingContainer parent.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

多次重复使用同一页面 的相关文章

随机推荐