0

我已经从 primefaces 多选树展示页面复制了 XHTML 和托管 bean 代码(对于基本树展示,我也得到了相同的结果)。

这是我的index.xhtml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</head>
<body>
    <h:form id="form">

        <p:growl id="messages" showDetail="true" escape="false" />

        <p:tree value="#{treeBean.root}" var="node" selectionMode="multiple"
            selection="#{treeBean.selectedNodes}" id="treeMultiple">

            <p:treeNode>
                <h:outputText value="#{node}" />
            </p:treeNode>
        </p:tree>

        <p:commandButton value="Display Selected" update="messages"
            actionListener="#{treeBean.displaySelectedMultiple}" id="btnDisplay" />

    </h:form>

</body>
</html>

这是豆子:

package org.primefaces.examples.view;

import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import org.primefaces.model.DefaultTreeNode;
import org.primefaces.model.TreeNode;

@ManagedBean
public class TreeBean implements Serializable {

    private TreeNode root;

    private TreeNode[] selectedNodes;

    public TreeBean() {
        root = new DefaultTreeNode("Root", null);
        TreeNode node0 = new DefaultTreeNode("Node 0", root);
        TreeNode node1 = new DefaultTreeNode("Node 1", root);
        TreeNode node2 = new DefaultTreeNode("Node 2", root);

        TreeNode node00 = new DefaultTreeNode("Node 0.0", node0);
        TreeNode node01 = new DefaultTreeNode("Node 0.1", node0);

        TreeNode node10 = new DefaultTreeNode("Node 1.0", node1);
        TreeNode node11 = new DefaultTreeNode("Node 1.1", node1);

        TreeNode node000 = new DefaultTreeNode("Node 0.0.0", node00);
        TreeNode node001 = new DefaultTreeNode("Node 0.0.1", node00);
        TreeNode node010 = new DefaultTreeNode("Node 0.1.0", node01);

        TreeNode node100 = new DefaultTreeNode("Node 1.0.0", node10);
    }

    public TreeNode getRoot() {
        return root;
    }

    public TreeNode[] getSelectedNodes() {
        return selectedNodes;
    }

    public void setSelectedNodes(TreeNode[] selectedNodes) {
        this.selectedNodes = selectedNodes;
    }

    public void displaySelectedMultiple(ActionEvent event) {
             if(selectedNodes != null && selectedNodes.length > 0) {
                 StringBuilder builder = new StringBuilder();

            for(TreeNode node : selectedNodes) {
                builder.append(node.getData().toString());
                builder.append("<br />");
            }


  FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Selected",builder.toString());

            FacesContext.getCurrentInstance().addMessage(null, message);
        }
    }
}

我得到的只是一个简单的列表:

• 节点 0
• 节点 1
• 节点 2

看起来缺少 Ajax、CSS 或/和 JavaScript 代码......但没有提到在展示中添加它。谢谢您的帮助!

tomcat 7 eclipse juno webapp 配置:jsf 2.1 动态webapp 3.0 java 6

4

0 回答 0