2013-02-15 60 views
0

我想創建由「標題」和「內容」組成的頁面。我創建common.xhtml春季Web流和JSF模板

<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」(在「header」中),這導致頁面 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」。是否有可能如何重寫它,同時牢記這些操作發生在這兩頁相同的「標題」中。

回答

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部分呈現

你會可能必須重新設計您的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?

+0

感謝@ rootkit007的答案。一個小的澄清:對於「內容」我有不同的頁面。所以我想顯示另一個頁面,而不是重新渲染同一頁面。據我所知,如果你想重新渲染同一頁面或者我錯了,「部分渲染」是合適的? – chaldaean 2013-02-19 10:35:47

+0

我添加了XHTML示例。部分渲染適合重新渲染當前頁面的某些部分,而無需刷新其他所有內容,這是正確的 – rootkit 2013-02-19 18:41:25