【问题标题】:Recursion with include and h:datatable [duplicate]使用 include 和 h:datatable 进行递归 [重复]
【发布时间】:2015-10-28 23:45:48
【问题描述】:

我在尝试recursively include pages 时遇到了一些麻烦。问题是所有的包含实际上都发生了,但是 h:dataTable 发生了一些事情,所以第二个包含的数据表内容没有显示出来。我猜这个问题来自与 var post 并发本身。它可以在没有数据表的情况下工作。

所以我从 page.xhtml 调用 post_view2.xhtml 的包含:

<ui:include src="/template/includes/post_view2.xhtml" >
    <ui:param name="postList" value="#{watchThread.listeFirstPosts}"></ui:param>
    <ui:param name="count" value="8"></ui:param>            
</ui:include> 

计数设置为 8。

这是 post_view2.xhtml:

<ui:composition xmlns=....>
<h:dataTable var="post" value="#{postList}" styleClass="fullWidth">
<h:column>      
            #{post.posts.size()} <!-- gives a size higher than 0 -->
    <h:outputText value="#{watchThread.sanitize(post.content)}"/>

    <c:if test="${count gt 0}">                 
        <ui:include src="/template/includes/post_view2.xhtml">
            <ui:param name="postList" value="#{post.replies}"></ui:param>
            <ui:param name="count" value="${count-1}"></ui:param>
        </ui:include>
    </c:if>
</h:column>
</h:dataTable>
</ui:composition>

请注意,在第一个包含 post var 时,它等于一个列表。在第二个包括我试图使它等于另一个列表,我认为这就是导致问题的原因。我不知道为什么,也不知道如何解决。 附带说明一下,我使用的是 jstl c:if,但如果有另一种纯 jsf 的解决方案,我会接受 primefaces。

【问题讨论】:

  • “仅在我第一次调用时包含”是什么意思?下次您重新加载(导航到相同的)页面时,它不会显示嵌套表格,对吧?
  • @Guillermo 不,我措辞错误。所有的包含实际上都发生了,但是 h:dataTable 发生了一些事情,使得它不会显示第二个包含的数据表内容。我希望我把它清理干净了。

标签: jsf jsf-2 jstl


【解决方案1】:

我找到了一些解决方法,但我会让这个问题没有答案。

我没有使用 DataTable,而是使用了 jsp 标签 forEach,它可以工作。

所以不要这样:

<h:dataTable var="post" value="#{postList}">

我有:

<c:forEach var="post" items="#{postList}">

我不知道为什么这有效而 dataTable 无效。如果有人知道,请展开。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-03
    • 2010-11-24
    • 2020-11-30
    • 2014-09-14
    • 2011-06-04
    • 2018-11-02
    • 2015-02-02
    • 2012-07-08
    相关资源
    最近更新 更多