Reusing the same page multiple times

女生的网名这么多〃 提交于 2019-12-22 06:23:26

问题


Is it possible to reuse one page multiple times attached to different objects?

I have a page were you can input personal information (name, address, social number, ...) connect to one bean: prospect. In some occasions I must gather linked personal information. example for credit scoring (a person and a guarantor).

So I wanted to use with 2 includes. But how can I make sure include1 holds the information for person1 and include2 holds the information for 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>

and facescontext

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

I found 2 possible work arounds: -duplicate the page and define 2 beans in faces-config (pointing to the same java class) -do not use tabpanel and include, but enter person1 info , then save it and load person2 info and save person2.

Workaround1 negative point is that it is maintaining the same code twice. Workaround2 negative point is that it is not so 'cool' (ux point of view)


回答1:


You can use <ui:param> to pass parameters to <ui:include>:

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

With the above example, in each include the desired person will be available as #{person}. Those <f:subview> tags are to prevent duplicate component ID errors because they end up within the same UINamingContainer parent.



来源:https://stackoverflow.com/questions/7764545/reusing-the-same-page-multiple-times

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