【问题标题】:Spring web-flow and JSF templatingSpring Web 流和 JSF 模板
【发布时间】:2013-02-15 12:57:00
【问题描述】:

我想创建由“标题”和“内容”组成的页面。我创建 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”(在“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”。是否有可能重写它,记住这些操作发生在“标题”中,这两个页面是相同的。

【问题讨论】:

    标签: jsf spring-webflow


    【解决方案1】:

    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?

    【讨论】:

    • 感谢@rootkit007 的回答。一个小的澄清:对于“内容”,我有不同的页面。所以我想显示另一个页面,而不是重新渲染同一页面。据我了解,如果您想重新渲染同一页面或者我错了,“部分渲染”是合适的?
    • 我添加了 XHTML 示例。您是正确的,部分渲染适用于重新渲染当前页面的部分而不刷新其他所有内容
    猜你喜欢
    • 2012-12-17
    • 1970-01-01
    • 2020-11-12
    • 2012-08-10
    • 1970-01-01
    • 2012-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多