首先,我下载了例子,然后取部分代码。
他例子中的operamasks.xml好像是设置backbean的。我就没有用他的operamasks.xml用自己的faces-config.xml配置的
现在的问题是能加载出bean中的tree但是单击节点之后并没有触发相应的事件
他的例子之中用的都是断言。我也就用了在页面w:tree中添加onclick/onselect=“tree_onselect”都不走tree_onselect方法——————希望有狠人帮我解决问题。
项目很急,代码如下:页面主要代码:
"java"
<w:head>
<om:useBean value="categoryTreeBean"/>
</w:head>
<layout:borderLayout height="450">
<layout:panel region="west" width="150" title="tree" split="true">
<w:tree id="treeData" border="false" style="height:100%;width:100%;"/>
</layout:panel>
<layout:panel region="center" title="message">
<h:outputText id="response" escape="false"></h:outputText>
</layout:panel>
</layout:borderLayout>
类的全部代码:
"java"package com.wenice.web.backbean.category;import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.component.tree.base.TreeDataProvider2;
import org.operamasks.faces.component.tree.base.TreeDataProviderAdapter;
import org.operamasks.faces.component.tree.impl.UITree;
import org.operamasks.faces.component.tree.impl.UITreeNode;
public class CategoryTreeBean {    @Bind
    private UITree tree;
    @Bind
    private String response;
    @Bind
    private TreeDataProvider2 treeData = new TreeDataProviderAdapter() {
        public Object[] getChildren(Object node) {
            if (node == null) {
                return new Object[] { "root" };
            }
            if (node == "root") {
                return new Object[] { "node1", "node2", "node3" };
            }
            if (node == "node1") {
                return new Object[] { "node11", "node12", "node13" };
            }
            if (node == "node2") {
                return new Object[] { "node21", "node22" };
            }
            if (node == "node3") {
                return new Object[] { "node31" };
            }
            return null;
        }        public Boolean isChecked(Object node) {
            //return !("root".equals(node));
            return null;
        }        public boolean isCascade(Object node) {
            return true;
        }        public String getIcon(Object node) {
            return "";
        }        public String getText(Object node) {
            return node.toString();
        }        public String getHref(Object node) {
            return null;
        }        public String getHrefTarget(Object node) {
            return null;
        }        public boolean isExpanded(Object arg0) {
            return false;
        }        @Override
        public String getId(Object userData) {
            return userData.toString();
        }
    };    @Action(id="tree_onselect", event="onclick")
    public void tree_onselect() {
        System.out.println("-----tree_onselect-----star");
        printTreeState();
    }    @Action
    public void tree_oncheck() {
        System.out.println("-----tree_oncheck-----star");
        printTreeState();
    }    @Action
    public void tree_oncollapsenode() {
        System.out.println("-----tree_oncollapsenode-----star");
        printTreeState();
    }    @Action
    public void tree_onexpandnode() {
        System.out.println("-----tree_onexpandnode-----star");
        printTreeState();
    }    private void printTreeState() {
        if (tree == null) {
            return;
        }
        response = "当前事件信息:<br/>事件名:" + tree.getEventName() + "<br/>";
        if (tree.getEventNode() != null) {
            response += "响应事件的节点是:" + tree.getEventNode().getText();
        }
        if (tree.getCheckedNodes() != null) {
            response += "<br/><br/>当前树的状态是:<br/>";
            response += "勾中的节点是:";
            for (UITreeNode node : tree.getCheckedNodes()) {
                response += node.getText() + ",";
            }
        }
        if (tree.getSelectedNode() != null) {
            response += "<br/>选中的节点是:";
            response += tree.getSelectedNode().getText();
        }
    }
}