【问题标题】:Lazy loading parts of seam pages?延迟加载部分接缝页?
【发布时间】:2009-04-29 16:42:39
【问题描述】:

我正在开发一个接缝应用程序(JBoss AS 4.2.2 下的 2.1.1.GA),其中一个特定的部分(有时很大)在用户与该特定部分交互之前不需要呈现部分,请按照文章标题的思路来思考,用户单击标题并展开以显示包含文本的框。

我可以使用 Seam 和 Richfaces 毫无问题地实现这一点,但是当用户第一次加载页面时,所有部分的内容都会下载到浏览器中。无论如何,这些部分(可能包含也可能不包含richfaces控件本身)是否可以使用ajax按需下载?

谢谢。

【问题讨论】:

    标签: ajax seam richfaces


    【解决方案1】:

    方法很多。

    只需在框上设置render="false",然后在单击标题时重新渲染它的父容器。

    例如。在您的支持 Bean 中有一个名为 showContent 的布尔值,由 toggleContent() 方法切换:

    <a4j:commandLink 
       value="This is a title" 
       ajaxSingle="true" 
       reRender="contentDiv" 
       action="#{someBackingBean.toggleContent}"/>
    
    <a4j:outputPanel id="contentDiv">
       <a4j:outputPanel rendered="#{someBackingBean.showContent}">
          This is some text that is not rendered when the page loads
       </a4j:outputPanel>
    </a4j:outputPanel>
    

    编辑:回应评论。另一种方法是使用 a4j:jsFunction(非常方便)和一些 javascript。

    <h1 onclick="toggleContent(this);">This is a title</h1>
    <a4j:outputPanel id="contentDiv">
       <a4j:outputPanel rendered="#{someBackingBean.showContent}">
          This is some text that is not rendered when the page loads
       </a4j:outputPanel>
    </a4j:outputPanel>
    
    <script>
    function toggleContent(element) {
       //check if the contentDiv has any contents (maybe check if element has a child under contentDiv)
    
       //if it doesn't then call a4j:jsFunction to load the contentDiv eg. loadContent();
    
       //hide or show div depending on the current state of it
    }
    </script>
    
    <a4j:jsFunction name="loadContent" action="#{someBackingBean.toggleContent}" reRender="contentDiv"/>
    

    反正就是这样。

    【讨论】:

    • 这确实有效,但确实意味着每次切换时都必须下载内容。这对于较小的部分来说很好(对于我们来说往往是那些必须完全重新渲染的控件),但对于较大的部分可能会很烦人。理想情况下,我们正在寻找一种方法来一次性下载这些较大的数据块。
    • a4j:jsFunction 会有所帮助。我已经添加了一个非常粗略的大纲,说明你如何做到这一点。
    【解决方案2】:

    如果您使用可滚动表格怎么办。如何实现分块获取数据?

    拉加兹 马尔科

    【讨论】:

      猜你喜欢
      • 2016-06-12
      • 2022-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-19
      • 1970-01-01
      • 1970-01-01
      • 2016-03-06
      相关资源
      最近更新 更多