【问题标题】:JSF Primefaces treetable expand not working when updated through ajax通过 ajax 更新时,JSF Primefaces 树表扩展不起作用
【发布时间】:2013-12-28 11:26:21
【问题描述】:

在我的第一页中,我展示了一个加载树表的命令按钮。

树表显示,但expand node is not working

我正在使用 primefaces 4.0、jsf 2.2

这是我的代码,

首页支持 bean

@ManagedBean(name="loadBean")
public class AjaxLoadBean {
private boolean show;
private String currentPage;

public boolean isShow() {
    return show;
}

public void setShow(boolean show) {
    this.show = show;
}

public String getCurrentPage() {
    return currentPage;
}

public void setCurrentPage(String currentPage) {
    this.currentPage = currentPage;
}

public void newPage() {
    show = true;
    currentPage = "treeTable.xhtml";
}
}

首页

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">

<h:head></h:head>
<h:body>
<h:form>
    <p:commandButton value="Show" actionListener="#{loadBean.newPage}"
        update=":content" />
</h:form>

<h:panelGroup id="content">
    <h:panelGroup rendered="#{loadBean.show}">
        <ui:include src="#{loadBean.currentPage}"></ui:include>
    </h:panelGroup>
</h:panelGroup>
</h:body>
</html>

treeTable.xhtml

我去掉了 ui:composition 标签,

<h:form styleClass="form-horizontal">
<p:treeTable value="#{treeTableBean.root}" var="dataElement"
                id="table">
<p:column headerText="No.">
    <h:outputText value="#{dataElement.no}" />
</p:column>

<p:column headerText="Name">
    <h:outputText value="#{dataElement.name}" />
</p:column>

<p:column headerText="select">
    <p:selectBooleanCheckbox value="#{dataElement.select}" />
</p:column>
</p:treeTable>
</h:form>

TreeTableBean

@ManagedBean
public class TreeTableBean implements Serializable{
private static final long serialVersionUID = 1L;
private TreeNode root;

public TreeTableBean() {
    root = new DefaultTreeNode("root", null);

    new DefaultTreeNode(new TreeTableData(2, "N2", true), root);
    new DefaultTreeNode(new TreeTableData(3, "N3", true), root);
    new DefaultTreeNode(new TreeTableData(4, "N4", true), root);

    TreeNode subNode = new DefaultTreeNode(new TreeTableData(5, "N5", true), root);
    new DefaultTreeNode(new TreeTableData(1, "N5.1", true), subNode);
    new DefaultTreeNode(new TreeTableData(2, "N5.2", false), subNode);
    subNode.setExpanded(true);
}

public TreeNode getRoot() {
    return root;
}
}

【问题讨论】:

    标签: jsf jsf-2 primefaces treetable


    【解决方案1】:

    我将两个 bean 都更改为 ViewScoped,它正在工作。

    Viewscoped 是支持 ajax 调用所需的最小值 数据表、树等组件

    我在 primefaces 论坛上发帖并获得了该信息。

    http://forum.primefaces.org/viewtopic.php?f=3&t=35620#p113774

    【讨论】:

      【解决方案2】:

      我也有这个问题。我确实通过以下步骤解决了: 第 1 步:将您的 XHTML 文件移动到 webcontent 文件夹中。第2步:由于webcontent中的所有文件都允许公共访问,出于安全原因,您需要在web.xml中添加以下条目。

      请点击链接了解安全限制:JSF 2: Composite components inside WEB-INF

      【讨论】:

        【解决方案3】:

        这里没有任何api库简单的解决方案代码。使用 JSF 2.X,Facelets 递归 ui:include ...

        主页代码是文件名:WHPlaceResults.xhtml

        <ui:composition template="/Templates/frm.xhtml" xmlns="http://www.w3.org/1999/xhtml" xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:c="http://xmlns.jcp.org/jsp/jstl/core" xmlns:fn="http://xmlns.jcp.org/jsp/jstl/functions" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich" xmlns:p="http://primefaces.org/ui">
        <ui:define name="FRM_NW">
            <!-- TODO -->
        </ui:define>
        <ui:define name="FRM_NC">
            <!-- TODO -->
        </ui:define>
        <ui:define name="FRM_C">
            <!-- TODO -->
            <a4j:outputPanel rendered="#{WHMBean.places.hasResults}" layout="block">
                <table width="100%" cellpadding="5" cellspacing="1" class="res">
                    <ui:fragment rendered="#{WHMBean.placeSearcher.viewAsIsTREE}">
                        <tr class="hdr">
                            <td width="25"></td>
                            <td>
                                <h:outputText value="#{cmn['lbl.name']}" />
                            </td>
                            <td width="125">
                                <h:outputText value="#{cmn['lbl.status']}" />
                            </td>
                            <td width="125">
                                <h:outputText value="#{cmn['lbl.date.reg']}" />
                            </td>
                        </tr>
                        <c:forEach items="#{CoreMBeanUtilities.getWHPlaces(WHMBean.placeSearcher.statusType, null)}" var="entity">
                            <tr class="row">
                                <td>
                                    <h:outputText value="#{WHMBean.places.pager.offset + rowKey + 1}" title="#{entity.id}" />
                                </td>
                                <td style="text-align: left">
                                    <a4j:commandLink value="#{entity.shorTitle}" />
                                </td>
                                <td>
                                    <h:outputText value="#{cmn[entity.statusTypeBundle]}" />
                                </td>
                                <td>
                                    <h:outputText value="#{entity.regDate}">
                                        <f:convertDateTime timeZone="#{CoreMBeanUtilities.systemTimeZone}" pattern="#{CoreMBeanUtilities.datePatternResults}" />
                                    </h:outputText>
                                </td>
                            </tr>
                            <ui:include src="#{entity.pageTreeRecurs}">
                                <ui:param name="lvl" value="#{1}" />
                                <ui:param name="parent" value="#{entity}" />
                            </ui:include>
                        </c:forEach>
                    </ui:fragment>
                    <ui:fragment rendered="#{WHMBean.placeSearcher.viewAsIsTABLE}">
                        <!-- TODO -->
                    </ui:fragment>
                </table>
            </a4j:outputPanel>
            <a4j:outputPanel rendered="#{!WHMBean.places.hasResults}" layout="block" styleClass="frm_info">
                <h:outputText value="#{WHMBean.placeSearcher.hasConditions?cmn['msg.res.none.conditions']:core['lbl.wh.place.res.none']}" />
            </a4j:outputPanel>
        </ui:define>
        <ui:define name="FRM_SW">
            <!-- TODO -->
        </ui:define>
        <ui:define name="FRM_SC">
            <!-- TODO -->
        </ui:define>
        <ui:define name="FRM_SE">
            <!-- TODO -->
        </ui:define>
        

        包含的递归页面代码是文件名:WHPlaceRecursiveResults.xhtml

        <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:c="http://xmlns.jcp.org/jsp/jstl/core" xmlns:fn="http://xmlns.jcp.org/jsp/jstl/functions" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich" xmlns:p="http://primefaces.org/ui">
        <c:forEach items="#{parent.childrens}" var="child">
            <tr class="row">
                <td />
                <td style="text-align: left; padding-left: #{lvl*20}px">
                    <a4j:commandLink value="#{child.shorTitle}" action="#{WHMBean.doPlaceDetails(child)}" render="NAV, ACTION, PAGE" status="CMN" execute="@this" />
                </td>
                <td>
                    <h:outputText value="#{cmn[child.statusTypeBundle]}" />
                </td>
                <td>
                    <h:outputText value="#{child.regDate}">
                        <f:convertDateTime timeZone="#{CoreMBeanUtilities.systemTimeZone}" pattern="#{CoreMBeanUtilities.datePatternResults}" />
                    </h:outputText>
                </td>
            </tr>
            <ui:include src="#{child.getHasChildrens() ? 'WHPlaceRecResults.xhtml' : '../../../CMN/none.xhtml'}">
                <ui:param name="lvl" value="#{lvl+1}" />
                <ui:param name="parent" value="#{child}" />
            </ui:include>
        </c:forEach>
        

        Example Here

        【讨论】:

          猜你喜欢
          • 2015-12-10
          • 2015-08-12
          • 1970-01-01
          • 2018-03-11
          • 1970-01-01
          • 2021-05-13
          • 2011-05-27
          • 2014-03-17
          • 2014-06-11
          相关资源
          最近更新 更多