Problemas com MyFaces e Tree2

1 resposta
V

Galera do Portal Java, estou tomando uma surra do tal tree2, quando ele monta a arvore e clico no docukmento para ele ir para algum lugar ele nao vai, fica dando submit na pagina.
Segue o meu JSF:

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        
        <h1>JSP Page</h1>
        
        <f:view>
            <h:form id="foo">
                <t:tree2 id="clientTree" value="#{TreeBacker.treeData}" var="node" varNodeToggler="t">
                    <f:facet name="person">
                        <h:panelGroup>
                            <f:facet name="expand">
                                <t:graphicImage value="imagens/PastaAzulAberta.gif" rendered="#{t.nodeExpanded}" border="0"/>
                            </f:facet>
                            <f:facet name="collapse">
                                <t:graphicImage value="images/yellow-folder-closed.png" rendered="#{!t.nodeExpanded}" border="0"/>
                            </f:facet>
                            <h:outputText value="#{node.description}" styleClass="nodeFolder"/>
                        </h:panelGroup>
                    </f:facet>
                    <f:facet name="foo-folder">
                        <h:panelGroup>
                            <f:facet name="expand">
                                <t:graphicImage value="images/yellow-folder-open.png" rendered="#{t.nodeExpanded}" border="0"/>
                            </f:facet>
                            <f:facet name="collapse">
                                <t:graphicImage value="images/yellow-folder-closed.png" rendered="#{!t.nodeExpanded}" border="0"/>
                            </f:facet>
                            <h:outputText value="#{node.description}" styleClass="nodeFolder"/>
                            <h:outputText value=" (#{node.childCount})" styleClass="childCount" rendered="#{!empty node.children}"/>
                        </h:panelGroup>
                    </f:facet>
                    <f:facet name="bar-folder">
                        <h:panelGroup>
                            <f:facet name="expand">
                                <t:graphicImage value="images/blue-folder-open.gif" rendered="#{t.nodeExpanded}" border="0"/>
                            </f:facet>
                            <f:facet name="collapse">
                                <t:graphicImage value="images/blue-folder-closed.png" rendered="#{!t.nodeExpanded}" border="0"/>
                            </f:facet>
                            <h:outputText value="#{node.description}" styleClass="nodeFolder"/>
                            <h:outputText value=" (#{node.childCount})" styleClass="childCount" rendered="#{!empty node.children}"/>
                        </h:panelGroup>
                    </f:facet>
                    <f:facet name="document">
                        <h:panelGroup>
                            <h:commandLink immediate="true" styleClass="#{t.nodeSelected ? 'documentSelected':'document'}" actionListener="#{t.setNodeSelected}">
                                <t:graphicImage value="images/document.png" border="0"/>
                                <h:outputText value="#{node.description}"/>
                                <f:param name="docNum" value="#{node.identifier}"/>
                            </h:commandLink>
                        </h:panelGroup>
                    </f:facet>
                </t:tree2>
                
            </h:form>
        </f:view>
        
    </body>
</html>

Segue agora a classe que estou chamando:

/*
 * TreeBacker.java
 *
 * Created on 2 de Agosto de 2007, 13:54
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.chart.teste;

import java.util.Iterator;
import org.apache.myfaces.custom.tree2.HtmlTree;
import org.apache.myfaces.custom.tree2.TreeNode;
import org.apache.myfaces.custom.tree2.TreeNodeBase;
import org.apache.myfaces.custom.tree2.TreeModel;
import org.apache.myfaces.custom.tree2.TreeModelBase;

import javax.faces.context.FacesContext;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.validator.ValidatorException;
import javax.faces.event.ActionEvent;
import javax.faces.component.html.HtmlOutputText;
import java.io.Serializable;
/**
 *
 * @author vinicius
 */
public class TreeBacker implements Serializable{
    
    /**
     * serial id for serialisation versioning
     */
    private static final long serialVersionUID = 1L;
    private TreeModelBase     _treeModel;
    private HtmlTree          _tree;
    private String  acaoSubmit;
    
    public TreeNode getTreeData() {
        TreeNode treeData = new TreeNodeBase("foo-folder", "Inbox", false);
        
        // construct a set of fake data (normally your data would come from a database)
        
        // populate Frank's portion of the tree
        TreeNodeBase personNode = new TreeNodeBase("person", "Frank Foo", false);
        personNode.getChildren().add(new TreeNodeBase("foo-folder", "Requires Foo", false));
        TreeNodeBase folderNode = new TreeNodeBase("foo-folder", "Requires Foo Reviewer", false);
        folderNode.getChildren().add(new TreeNodeBase("document", "X050001", true));
        folderNode.getChildren().add(new TreeNodeBase("document", "X050002", true));
        folderNode.getChildren().add(new TreeNodeBase("document", "X050003", true));
        personNode.getChildren().add(folderNode);
        personNode.getChildren().add(new TreeNodeBase("foo-folder", "Requires Foo Recommendation", false));
        folderNode = new TreeNodeBase("foo-folder", "Requires Foo Approval", false);
        folderNode.getChildren().add(new TreeNodeBase("document", "J050001", true));
        folderNode.getChildren().add(new TreeNodeBase("document", "J050002", true));
        folderNode.getChildren().add(new TreeNodeBase("document", "J050003", true));
        folderNode.getChildren().add(new TreeNodeBase("document", "E050011", true));
        folderNode.getChildren().add(new TreeNodeBase("document", "R050002", true));
        folderNode.getChildren().add(new TreeNodeBase("document", "C050003", true));
        personNode.getChildren().add(folderNode);
        folderNode = new TreeNodeBase("bar-folder", "Requires Bar Processing", false);
        folderNode.getChildren().add(new TreeNodeBase("document", "VCS.jsf", "teste", false));
        folderNode.getChildren().add(new TreeNodeBase("document", "X050011", true));
        folderNode.getChildren().add(new TreeNodeBase("document", "F050002", true));
        folderNode.getChildren().add(new TreeNodeBase("document", "G050003", true));
        personNode.getChildren().add(folderNode);
        folderNode = new TreeNodeBase("bar-folder", "Requires Bar Approval", false);
        folderNode.getChildren().add(new TreeNodeBase("document", "J050006", true));
        folderNode.getChildren().add(new TreeNodeBase("document", "J050007", true));
        personNode.getChildren().add(folderNode);
        
        treeData.getChildren().add(personNode);
        
        // populate Betty's portion of the tree
        personNode = new TreeNodeBase("person", "Betty Bar", false);
        personNode.getChildren().add(new TreeNodeBase("foo-folder", "Requires Foo", false));
        folderNode = new TreeNodeBase("foo-folder", "Requires Foo Reviewer", false);
        folderNode.getChildren().add(new TreeNodeBase("document", "X012000", true));
        folderNode.getChildren().add(new TreeNodeBase("document", "X013000", true));
        folderNode.getChildren().add(new TreeNodeBase("document", "X014000", true));
        personNode.getChildren().add(folderNode);
        folderNode = new TreeNodeBase("foo-folder", "Requires Foo Recommendation", false);
        folderNode.getChildren().add(new TreeNodeBase("document", "J010026", true));
        folderNode.getChildren().add(new TreeNodeBase("document", "J020002", true));
        folderNode.getChildren().add(new TreeNodeBase("document", "J030103", true));
        folderNode.getChildren().add(new TreeNodeBase("document", "E030214", true));
        folderNode.getChildren().add(new TreeNodeBase("document", "R020444", true));
        folderNode.getChildren().add(new TreeNodeBase("document", "C010000", true));
        personNode.getChildren().add(folderNode);
        personNode.getChildren().add(new TreeNodeBase("foo-folder", "Requires Foo Approval", false));
        folderNode = new TreeNodeBase("bar-folder", "Requires Bar Processing", false);
        folderNode.getChildren().add(new TreeNodeBase("document", "T052003", true));
        folderNode.getChildren().add(new TreeNodeBase("document", "T020011", true));
        personNode.getChildren().add(folderNode);
        folderNode = new TreeNodeBase("bar-folder", "Requires Bar Approval", false);
        folderNode.getChildren().add(new TreeNodeBase("document", "J010002", true));
        folderNode.getChildren().add(new TreeNodeBase("document", "J030047", true));
        folderNode.getChildren().add(new TreeNodeBase("document", "F030112", true));
        personNode.getChildren().add(folderNode);
        
        treeData.getChildren().add(personNode);
        
        return treeData;
    }
    
    /**
     * NOTE: This is just to show an alternative way of supplying tree data.  You can supply either a
     * TreeModel or TreeNode.
     *
     * @return TreeModel
     */
    public TreeModel getExpandedTreeData() {
        return new TreeModelBase(getTreeData());
    }
    
    public void setTree(HtmlTree tree) {
        _tree = tree;
    }
    
    public HtmlTree getTree() {
        return _tree;
    }
    
    public String expandAll() {
        _tree.expandAll();
        return null;
    }
    
    private String _nodePath;
    
    public void setNodePath(String nodePath) {
        _nodePath = nodePath;
    }
    
    public String getNodePath() {
        return _nodePath;
    }
    
    public void checkPath(FacesContext context, UIComponent component, java.lang.Object value) {
        // make sure path is valid (leaves cannot be expanded or renderer will complain)
        FacesMessage message = null;
        
        String[] path = _tree.getPathInformation(value.toString());
        
        for (int i = 0; i < path.length; i++) {
            String nodeId = path[i];
            try {
                _tree.setNodeId(nodeId);
            } catch (Exception e) {
                throw new ValidatorException(message, e);
            }
            
            if (_tree.getNode().isLeaf()) {
                message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Invalid node path (cannot expand a leaf): "
                        + nodeId, "Invalid node path (cannot expand a leaf): " + nodeId);
                throw new ValidatorException(message);
            }
        }
    }
    
    public void expandPath(ActionEvent event) {
        _tree.expandPath(_tree.getPathInformation(_nodePath));
    }
    
    public String submit() {
        return acaoSubmit;
    }
    public void process(ActionEvent event) {
        UIComponent component = (UIComponent) event.getSource();
        Iterator iterator = component.getFacetsAndChildren();
        while (iterator.hasNext()) {
            Object object = iterator.next();
           
                HtmlOutputText htmlOutputText = (HtmlOutputText) object;
// Comparando o valor com a descricao dos nodos
                if (htmlOutputText.getValue().equals("VCS")) {
                    this.acaoSubmit = "teste";
                } else if (htmlOutputText.getValue().equals("Primeira Opcao Segundo nodo")) {
                    this.acaoSubmit = "go_segundoNivel";
                } else {
                    this.acaoSubmit = "";
                }
            
        }
    }
}

La no commandLink eu devo colocar um action? Pq eu estou testando atraves #{node.identifier} mas nunca mais que faz a mudança de pagina.

Valeu mais uma vez Galera

1 Resposta

M

olá,

você tem o managed bean (node) declarado? Tens a action identifier? Ela retorna um outcome que tenha um navigation case para outra página? Veja estes detalhes, qualquer dúvida… poste aqui.

:okok:

Criado 6 de agosto de 2007
Ultima resposta 7 de ago. de 2007
Respostas 1
Participantes 2