通过ajax更新时,JSF Primefaces treetable扩展不起作用

时间:2013-12-28 11:26:22

标签: jsf jsf-2 primefaces treetable

在我的第一页中,我显示了一个加载treetable的命令按钮。

显示treetable但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;
}
}

3 个答案:

答案 0 :(得分:0)

我将两个bean都更改为ViewScoped,它正在运行。

  

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

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

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

答案 1 :(得分:0)

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

请关注安全限制的链接:JSF 2:WEB-INF中的复合组件

答案 2 :(得分:0)

这里没有任何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