Sawan Vithlani <vithlani.lists <at> gmail.com> writes:

> 
> 
> Would be worth it if you posted your JSP and backing bean code along with 
your
question....Sawan
> 
> On 12/15/06, Sanjeev Gour <
> sanjeev.gour <at> gmail.com> wrote:Hi,I am using tomahwk tree2 in  my example
but clicking on a leaf node
> is causing the following exception:java.lang.ClassCastException:
org.apache.myfaces.custom.tree2.TreeStateBase       
org.apache.myfaces.custom.tree2.UITreeData.restoreState(UITreeData.java:111)
>
        org.apache.myfaces.custom.tree2.HtmlTree.restoreState(HtmlTree.java:95)
      
javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:
1007)
       javax.faces.component.UIComponentBase.processRestoreState
>
(UIComponentBase.java:1019)       
javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:
1019)
      
com.sun.faces.application.StateManagerImpl.restoreComponentState(StateManager
Impl.java
>
:352)       
com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:
240)
      
com.sun.faces.application.ViewHandlerImpl.restoreView(ViewHandlerImpl.java:
228)
       com.sun.faces.lifecycle.RestoreViewPhase.execute
>
(RestoreViewPhase.java:157)       
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)       
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)       
javax.faces.webapp.FacesServlet.service
>
(FacesServlet.java:197)       
org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.
java:100)
      
org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.
java:147)
> I am unable to understand why this is coming. I have specified filter
mapping
inmy web.xml. Can somwbody please help?Thanks.Sanjeev.
> 
> 
> 
> 

Hi,
Thanks for your time. This is one example found on net with little
modifications. One point to note here is that I noticed that the
ExtensionListener is not configured correctly. Here is my web.xml code: 

<?xml version="1.0"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee";
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd";>
 <display-name>Test</display-name>
 <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
 </context-param>

 <listener>
  <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
 </listener>
 
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet>
    <servlet-name>SourceCodeServlet</servlet-name>
   
<servlet-class>org.apache.myfaces.shared_tomahawk.util.servlet.
SourceCodeServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>SourceCodeServlet</servlet-name>
    <url-pattern>*.source</url-pattern>
  </servlet-mapping>
 
 
 <!-- Faces Servlet -->
 
 <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
 </welcome-file-list> 
 <login-config>
  <auth-method>BASIC</auth-method>
 </login-config>
 
 <context-param>
    <description>This parameter tells MyFaces if javascript code should be
allowed in the rendered HTML output. If javascript is allowed, command_link
anchors will have javascript code that submits the corresponding form.
If javascript is not allowed, the state saving info and nested
parameters will be added as url parameters.
            Default: "true"</description>
    <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
    <param-value>false</param-value>
  </context-param>
  <context-param>
    <description>If true, rendered HTML code will be formatted, so that it is
"human readable".
            i.e. additional line separators and whitespace will be written,
            that
do not
            influence the HTML code.
            Default: "true"</description>
    <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <description>If true, a javascript function will be rendered that is 
able to restore the
former vertical scroll on every request. Convenient feature if you
have pages with long lists and you do not want the browser page to always jump
to the top if you trigger a link or button action that stays on the same page.
            Default: "false"</description>
    <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
    <param-value>true</param-value>
  </context-param>

    <context-param>
                <description>
                        Validate managed beans, navigation rules and ensure
                        that forms are not nested.
                </description>
        <param-name>org.apache.myfaces.VALIDATE</param-name>
        <param-value>true</param-value>
    </context-param>

  <context-param>
    <description>A class implementing the
                    org.apache.myfaces.shared.renderkit.html.util.AddResource
                    interface. It is responsible to
                place scripts and css on the right position in your HTML 
                        document.
            Default:
"org.apache.myfaces.shared.renderkit.html.util.DefaultAddResource"
            Follow the description on the MyFaces-Wiki-Performance page to
            enable
            StreamingAddResource instead of DefaultAddResource if you want to
            gain performance.
    </description>
    <param-name>org.apache.myfaces.ADD_RESOURCE_CLASS</param-name>
   
<param-value>org.apache.myfaces.renderkit.html.util.DefaultAddResource
</param-value>
   
<!--param-value>org.apache.myfaces.component.html.util.StreamingAddResource
</param-value-->
  </context-param>

  <context-param>
    <description>
        A very common problem in configuring MyFaces-web-applications
        is that the Extensions-Filter is not configured at all
        or improperly configured. This parameter will check for a properly
        configured Extensions-Filter if it is needed by the web-app.
        In most cases this check will work just fine, there might be cases
        where an internal forward will bypass the Extensions-Filter and the 
        check
        will not work. If this is the case, you can disable the check by 
        setting
        this parameter to false.
    </description>
    <param-name>org.apache.myfaces.CHECK_EXTENSIONS_FILTER</param-name>
    <param-value>false</param-value>
  </context-param>

  <context-param>
    <description>
        Change the url-pattern from the ExtensionsFilter
        Default is "/faces/myFacesExtensionResource"
        Note: The filter-mapping for ExtensionsFilter, the url-pattern is
        this value + "/*", else there comes a exception
    </description>
    <param-name>org.apache.myfaces.RESOURCE_VIRTUAL_PATH</param-name>
    <param-value>/faces/extensionResource</param-value>
  </context-param>
 
<filter>
        <filter-name>MyFacesExtensionsFilter</filter-name>
        <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter
        </filter-class>
    <init-param>
        <description>
                                Set the size limit for uploaded files.
                                 Format: 10 - 10 bytes
                    10k - 10 KB
                    10m - 10 MB
                    1g - 1 GB
        </description>

        <param-name>maxFileSize</param-name>
        <param-value>20m</param-value>
    </init-param>
</filter>

<!-- extension mapping for adding <script/>, <link/>, and other resource
tags to
JSF-pages  -->
<filter-mapping>
    <filter-name>MyFacesExtensionsFilter</filter-name>
    <!-- servlet-name must match the name of your
javax.faces.webapp.FacesServlet entry -->
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

<!-- extension mapping for serving page-independent resources (javascript,
stylesheets, images, etc.)  -->
<filter-mapping>
    <filter-name>MyFacesExtensionsFilter</filter-name>
    <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
</filter-mapping>

<!-- extension mapping for adding <script/>, <link/>, and other resource tags 
to
JSF-pages  -->
<filter-mapping>
    <filter-name>MyFacesExtensionsFilter</filter-name>
    <url-pattern>*.faces</url-pattern>
</filter-mapping>

</web-app>

Following is the exception I am gettin at application launch;


log4j:WARN No appenders could be found for logger
(org.apache.catalina.startup.TldConfig).
log4j:WARN Please initialize the log4j system properly.
java.lang.ClassCastException:
org.apache.myfaces.renderkit.html.util.ExtensionsPhaseListener
at com.sun.faces.config.ConfigureListener.configure(ConfigureListener.java:711)
at com.sun.faces.config.ConfigureListener.configure(ConfigureListener.java:398)
at
com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.
java:328)
at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:
3692)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4127)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:680)
at org.apache.catalina.startup.Catalina.start(Catalina.java:536)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:275)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Dec 18, 2006 12:21:12 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart

This is my jsp code:

<%@ 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"%>

<html>
<[EMAIL PROTECTED] file="inc/head.inc" %>
<body>
        <f:view>
                <h:form id="foo">
                    <t:tree2 id="clientTree" value="#{treeBacker.treeData}"
                    var="node"
varNodeToggler="t" showRootNode="false">
                        <f:facet name="person">
                             <t:graphicImage value="images/yellow-folder-closed
                             .png"
rendered="false" border="0" id="d"/>
                         </f:facet>
                         <f:facet name="collapse">
                             <t:graphicImage value="images/yellow-folder-closed
                             .png"
rendered="true" border="0"/>
                        </f:facet>
                        <f:facet name="foo-folder">
                             <h:panelGroup>
                                <f:facet name="expand">
                                    <t:graphicImage value="images/yellow-folder
                                    -open.png"
rendered="true" border="0"/>
                                </f:facet>
                                <f:facet name="collapse">
                                    <t:graphicImage value="images/yellow-folder
                                    -closed.png"
rendered="false" border="0"/>
                                </f:facet>
                                <h:outputText value="#{node.description}"
styleClass="nodeFolder"/>
                            </h:panelGroup>
                        </f:facet>
                        <f:facet name="bar-folder">
                                    <t:graphicImage value="images/blue-folder
                                    -open.gif"
rendered="true" border="0" id="o"/>
                        </f:facet>
                        <f:facet name="document">
                        <h:panelGroup>
                                          <t:graphicImage value="images/
                                          document.png" border="0" id="v"/>
                                          <h:commandLink value="click" 
                                          action="success"/>
                                </h:panelGroup>      
                                <h:panelGroup>
                                        <h:commandLink immediate="true" 
                                        action="success"
actionListener="#{navigationBacker.processAction}">
                                <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>

and this is java bean:

package org.apache.myfaces.examples.tree;

import javax.faces.component.UIComponent;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;

import org.apache.myfaces.custom.tree2.HtmlTree;
import org.apache.myfaces.custom.tree2.TreeNodeBase;

public class NavigationBacker {

        /**
     * Intercept when a lead node is expanded and load additional data.
     * @param event
     * @throws AbortProcessingException
     */
    public void processAction(ActionEvent event) throws
    AbortProcessingException {
            System.out.println("Entering processAction()");
            UIComponent component = (UIComponent) event.getSource();
            while (!(component != null && component instanceof HtmlTree)) {
                    component = component.getParent();
            }
            if (component != null) {
                    HtmlTree tree = (HtmlTree) component;
                    TreeNodeBase node = (TreeNodeBase) tree.getNode();
                    if (!tree.isNodeExpanded() && 
                    node.getChildren().size() == 0) {
                      
            }
    }
    
   
}

one more bean I have:

package org.apache.myfaces.examples.tree;
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 java.io.Serializable;

/**
 * Backer bean for use in example.  Basically makes a TreeNode available.
 *
 * @author Sean Schofield
 * @version $Revision: 472610 $ $Date: 2006-11-08 19:46:34 +0000 (Wed, 08 Nov
2006) $
 */
public class TreeBacker implements Serializable
{
    /**
     * serial id for serialisation versioning
     */
    private static final long serialVersionUID = 1L;
    private HtmlTree          _tree;
    private String activeNodeId;
    public TreeNode getTreeData()
    {
        TreeNode treeData = new TreeNodeBase("foo-folder", "First", 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("foo-folder", "Accounting",
false);
        TreeNodeBase income = new TreeNodeBase("foo-folder", "Income", false);
        income.getChildren().add(new TreeNodeBase("document", "expense", true))
        ;
        personNode.getChildren().add(income);
        
       // personNode.getChildren().add(new TreeNodeBase("foo-folder", "Requires
Foo 1", 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", "X050003",
        true));
        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));
    }
}


Please help.

Thanks,
Sanjeev.




Reply via email to