2013-02-15 53 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