我正在开发一个接缝应用程序(JBoss AS 4.2.2 下的 2.1.1.GA),其中一个特定的部分(有时很大)在用户与该特定部分交互之前不需要呈现,认为沿着文章标题的行,用户单击标题并展开以显示包含文本的框。
我可以使用 Seam 和 Richfaces 毫无问题地实现这一点,但是当用户第一次加载页面时,所有部分的内容都会下载到浏览器中。无论如何,这些部分(可能包含也可能不包含richfaces控件本身)是否可以使用ajax按需下载?
谢谢。
很多方法。
只需在框上设置 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"/>
反正是这样的。
如果您使用可滚动表格怎么办。如何实现分块获取数据?
拉加兹·马尔科