Spring web-flow和JSF模板

时间:2013-02-15 12:57:01

标签: jsf spring-webflow

我想创建由“标题”和“内容”组成的页面。我创建了common.xhtml

<ui:insert name="header">
    <ui:include src="commonHeader.xhtml" />
</ui:insert>
<ui:insert name="content">
    <ui:include src="commonContent.xhtml" />
</ui:insert>

然后我创建两个页面(create_user_page.xhtml和search_page.xhtml),它们必须具有相同的“标题”但不同的“内容”

    <ui:composition  template="common.xhtml">
      <ui:define name="content">
                    <h1>Content for creating...</h1>
                    <ui:include src="create.xhtml"/>
      </ui:define>
    </ui:composition>

    <ui:composition template="common.xhtml">
      <ui:define name="content">
                    <h1>Content searching...</h1>
                    <ui:include src="search.xhtml"/>
      </ui:define>
    </ui:composition>

在我的web_flow.xml中我有

<view-state id="start_page" view="administrator/main_page.xhtml">
    <transition on="create_user" to="create_user_page" />
    <transition on="find_user" to="search_page" />
    <transition on="back" to="back" />
</view-state>

<view-state id="create_user_page" view="administrator/create_user_page.xhtml">
    <transition on="create_user" to="create_user_page" />
    <transition on="find_user" to="search_page" />
</view-state>

<view-state id="search_page" view="administrator/search_page.xhtml">
    <transition on="create_user" to="create_user_page" />
    <transition on="find_user" to="search_page" />
</view-state>

在main_page.xhtml我有两个动作“create_user”和“find_user”(在“标题”中),它们通向页面 create_user_page.xhtml和search_page.xhtml。它们具有相似的“标题”,并且在“内容”方面有所不同。这一切都很好,但我有一些问题。

1)似乎每次进入create_user_page.xhtml或search_page.xhtml时都会重新呈现“标题”,否则我错了?是否有可能“标题”将保持不重新呈现,并且仅对“内容”进行更改。

2)在我的网络流xml中,我必须重复代码

<transition on="create_user" to="create_user_page" />
<transition on="find_user" to="search_page" />

表示“create_user_page”和“search_page”。是否可能有一些如何重写它,请记住这些操作发生在“标题”中,对于这两个页面是相同的。

1 个答案:

答案 0 :(得分:0)

JSF模板将始终重新呈现您的页眉/页脚。就个人而言,我不认为这是一个问题,除非你有一些真正的性能密集型。您可以通过以下方式避免重新呈现:

  1. 使用HTML框架http://www.w3schools.com/tags/tag_frameset.asp
  2. 部分渲染 - 在您的SWF流程中(请参阅http://static.springsource.org/spring-webflow/docs/2.0.x/reference/htmlsingle/spring-webflow-reference.html#view-transitions中的标记),或者像PrimeFaces部分渲染
  3. 如果使用任何一种方法,您可能不得不重新设计XHTML和流程 - 实际上,部分渲染将取代流程定义。类似的东西:

     <h:commandLink value="go to search page" actionListener="#{myBean.goToSearchPage}" update="content"></h:commandLink>
     <h:commandLink value="go to another page" actionListener="#{myBean.goToAnotherPage}" update="content"></h:commandLink>
    
    <h:panelGroup id="content">
     <h:panelGroup id="search-page" rendered="#{myBean.isThisSearchPage}">
       <!-- search page contents here -->
     </h:panelGroup>
     <h:panelGroup id="another-page" rendered="#{myBean.isThisAnotherPage}">
       <!-- another page contents here -->
     </h:panelGroup>
    </h:panelGroup>
    

    上述方法肯定不易维护,不推荐。使用标准SWF,并在视图更改时重新呈现页眉/页脚。您仍然可以在SWF视图中使用部分渲染来响应用户的输入,而无需重新渲染整个页面。

    关于第二个问题:您可以使用全局转换和流继承。见How to import globaltransitions.xml in myflow.xml?