我正在尝试使用RichFaces树实现。我已经子类化了treendeimpl类-下面是我的装饰器超类。我得到了上面的错误。当然我不是在实现javax.swing.tree.TreeNode——我是在实现org.richfaces.model.TreeNode
package com.base.view.tree;
import org.richfaces.model.TreeNode;
import org.richfaces.model.TreeNodeImpl;
import com.iLearn.model.base.Typed;
public abstract class TreeNodeDecorator<T extends Typed> extends TreeNodeImpl implements TreeNode {
public TreeNodeDecorator(T theData) {
super();
setData(theData);
}
private T data;
public abstract String getDisplayString();
public abstract boolean isLeaf();
public T getData() {
return data;
}
public void setData(T theData) {
data = theData;
}
public String getType() {
return getData().getType();
}
}
下面是XHTML文件:
<?xml version="1.0" encoding="UTF-8"?>
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:rich="http://richfaces.org/rich"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:cust="http://memarden.com">
<link href="CSS/navigation.css" rel="stylesheet" type="text/css" />
<h:body>
<h3>#{text['organization']}</h3>
<ui:composition template="template-restricted.xhtml">
<ui:define name="body_content">
<div class="sl-title">Manage Schools</div>
<div class="sr-content">
<h:form>
<h:commandButton class="k-button"
value="create New Sub Org"
action="#{manageOrgHierarchy.createNew}"/>
<rich:tree
id="orgTree"
value="#{manageOrgHierarchy.rootNodes}"
style="width:300px"
selectionType="ajax"
selectionChangeListener="manageOrgHierarchy.processTreeSelectionChange"
var="node">
<rich:treeNode><rich:inplaceInput value="#{node.data.nickName}" defaultLabel="click to edit"/></rich:treeNode>
</rich:tree>
<h:commandButton class="k-button"
value="create New Root Org"
action="#{manageOrgHierarchy.createNew()}"
rendered="#{userSession.isAdmin}"/>
<h:commandButton class="k-button"
value="#{text['save']}"
action="#{manageOrgHierarchy.save}"/>
</h:form>
</div>
</ui:define>
</ui:composition>
</h:body>
</html>
下面是堆栈跟踪:
Jul 11, 2015 11:49:12 PM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
SEVERE: Error Rendering View[/restricted/memes/manageSchools.xhtml]
java.lang.ClassCastException: com.iLearn.view.tree.OrganizationRichFacesTreeNode cannot be cast to javax.swing.tree.TreeNode
at org.richfaces.model.SwingTreeNodeDataModelImpl.isLeaf(SwingTreeNodeDataModelImpl.java:91)
at org.richfaces.component.AbstractTree.isLeaf(AbstractTree.java:441)
at org.richfaces.component.TreeRange.shouldIterateChildren(TreeRange.java:54)
at org.richfaces.component.AbstractTree.walkModelChildren(AbstractTree.java:508)
at org.richfaces.component.AbstractTree.walkModelChildren(AbstractTree.java:526)
at org.richfaces.component.AbstractTree.walkModel(AbstractTree.java:500)
at org.richfaces.renderkit.TreeEncoderBase.encodeTree(TreeEncoderBase.java:90)
at org.richfaces.renderkit.TreeEncoderFull.encode(TreeEncoderFull.java:41)
at org.richfaces.renderkit.TreeRendererBase.encodeTree(TreeRendererBase.java:85)
at org.richfaces.renderkit.html.TreeRenderer.doEncodeChildren(TreeRenderer.java:129)
at org.richfaces.renderkit.RendererBase.encodeChildren(RendererBase.java:158)
at javax.faces.component.UIComponentBase.encodeChildren(Unknown Source)
at javax.faces.component.UIComponent.encodeAll(Unknown Source)
at javax.faces.render.Renderer.encodeChildren(Unknown Source)
at javax.faces.component.UIComponentBase.encodeChildren(Unknown Source)
at javax.faces.component.UIComponent.encodeAll(Unknown Source)
at javax.faces.component.UIComponent.encodeAll(Unknown Source)
at javax.faces.component.UIComponent.encodeAll(Unknown Source)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(Unknown Source)
at com.sun.faces.application.view.MultiViewHandler.renderView(Unknown Source)
at javax.faces.application.ViewHandlerWrapper.renderView(Unknown Source)
at javax.faces.application.ViewHandlerWrapper.renderView(Unknown Source)
at org.apache.myfaces.tomahawk.application.ResourceViewHandlerWrapper.renderView(ResourceViewHandlerWrapper.java:169)
at javax.faces.application.ViewHandlerWrapper.renderView(Unknown Source)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(Unknown Source)
at com.sun.faces.lifecycle.Phase.doPhase(Unknown Source)
at com.sun.faces.lifecycle.LifecycleImpl.render(Unknown Source)
at javax.faces.webapp.FacesServlet.service(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:357)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.iLearn.security.authentication.AccessFilter.doFilter(AccessFilter.java:49)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.iLearn.utils.web.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:34)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Jul 11, 2015 11:49:12 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/ilearn] threw exception [com.iLearn.view.tree.OrganizationRichFacesTreeNode cannot be cast to javax.swing.tree.TreeNode] with root cause
java.lang.ClassCastException: com.iLearn.view.tree.OrganizationRichFacesTreeNode cannot be cast to javax.swing.tree.TreeNode
at org.richfaces.model.SwingTreeNodeDataModelImpl.isLeaf(SwingTreeNodeDataModelImpl.java:91)
at org.richfaces.component.AbstractTree.isLeaf(AbstractTree.java:441)
at org.richfaces.component.TreeRange.shouldIterateChildren(TreeRange.java:54)
at org.richfaces.component.AbstractTree.walkModelChildren(AbstractTree.java:508)
at org.richfaces.component.AbstractTree.walkModelChildren(AbstractTree.java:526)
at org.richfaces.component.AbstractTree.walkModel(AbstractTree.java:500)
at org.richfaces.renderkit.TreeEncoderBase.encodeTree(TreeEncoderBase.java:90)
at org.richfaces.renderkit.TreeEncoderFull.encode(TreeEncoderFull.java:41)
at org.richfaces.renderkit.TreeRendererBase.encodeTree(TreeRendererBase.java:85)
at org.richfaces.renderkit.html.TreeRenderer.doEncodeChildren(TreeRenderer.java:129)
at org.richfaces.renderkit.RendererBase.encodeChildren(RendererBase.java:158)
at javax.faces.component.UIComponentBase.encodeChildren(Unknown Source)
at javax.faces.component.UIComponent.encodeAll(Unknown Source)
at javax.faces.render.Renderer.encodeChildren(Unknown Source)
at javax.faces.component.UIComponentBase.encodeChildren(Unknown Source)
at javax.faces.component.UIComponent.encodeAll(Unknown Source)
at javax.faces.component.UIComponent.encodeAll(Unknown Source)
at javax.faces.component.UIComponent.encodeAll(Unknown Source)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(Unknown Source)
at com.sun.faces.application.view.MultiViewHandler.renderView(Unknown Source)
at javax.faces.application.ViewHandlerWrapper.renderView(Unknown Source)
at javax.faces.application.ViewHandlerWrapper.renderView(Unknown Source)
at org.apache.myfaces.tomahawk.application.ResourceViewHandlerWrapper.renderView(ResourceViewHandlerWrapper.java:169)
at javax.faces.application.ViewHandlerWrapper.renderView(Unknown Source)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(Unknown Source)
at com.sun.faces.lifecycle.Phase.doPhase(Unknown Source)
at com.sun.faces.lifecycle.LifecycleImpl.render(Unknown Source)
at javax.faces.webapp.FacesServlet.service(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:357)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.iLearn.security.authentication.AccessFilter.doFilter(AccessFilter.java:49)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.iLearn.utils.web.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:34)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
这看起来像是RichFaces代码中的一个bug,直到我听到一个RichFaces开发人员有不同的说法。我已经在PrimeFaces中重新实现了树,现在它工作得很好。