primefaces tree drag,drop ajax event

时间:2014-01-03 18:32:17

标签: ajax primefaces drag-and-drop tree tomcat7

我有这个错误:

  

jan 03,2014 6:43:56 PM com.sun.faces.context.PartialViewContextImpl   processPartial INFO:java.lang.ClassCastException:   javax.faces.event.ValueChangeEvent无法强制转换为   javax.faces.event.AjaxBehaviorEvent java.lang.ClassCastException:   javax.faces.event.ValueChangeEvent无法强制转换为   javax.faces.event.AjaxBehaviorEvent

xhtml中的树:

                <p:tree id="catTree"
                        value="#{listCatsRenderer.categoryTree}" var="ndt"
                        selectionMode="single" 
                        selection="#{listCatsRenderer.selectedNode}"
                        draggable="true"
                        droppable="true"
                        animate="true" styleClass="tree_general"
                        propagateSelectionUp="false"
                        dynamic="true"
                        >

                    <p:ajax event="dragdrop" listener="#{listCatsRenderer.onDragDrop}" update=":main:catTree"/>

                    <p:treeNode>
                        <p:inplace event="dblclick" editor="true" >
                            <h:inputText value="#{ndt.name}"/>
                        </p:inplace>
                    </p:treeNode>  
                </p:tree>

从bean加载:

@Named
@SessionScoped
public class ListCatsRenderer extends ARenderer implements Serializable {
.
.
.
@Override
public TreeNode getCategoryTree() {
    if (categoryTree == null) {
        updateCategoryTree(); //DBS load
    } 
    return categoryTree;
}

在任何dragdrop事件之后它会抛出异常。当我转向上面的条件时,它可以正常工作。知道为什么吗? 谢谢。

// EDIT 过程事件的代码,但是它永远不会到达那里

public void onDragDrop(TreeDragDropEvent event) {
    System.out.println("dragged: " + event.getDragNode());
    System.out.println("dropped: " + event.getDropNode() + " > " + event.getDropIndex());
}

完整的堆栈跟踪可能有所帮助:

  

jan 05,2014 11:50:28 AM   com.sun.faces.lifecycle.ProcessValidationsPhase执行警告:   java.lang.ClassCastException:javax.faces.event.ValueChangeEvent   无法转换为javax.faces.event.AjaxBehaviorEvent   javax.faces.FacesException:java.lang.ClassCastException:   javax.faces.event.ValueChangeEvent无法强制转换为   javax.faces.event.AjaxBehaviorEvent at   com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:270)     在   org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:57)     在   javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1193)     在   com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)     在com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)at   com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)     在javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)     在   org.jboss.weld.servlet.ConversationFilter.doFilter(ConversationFilter.java:66)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)     在   org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)     在   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)     在   org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)     在   org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)     在   org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:589)     在   org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:310)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:615)     在java.lang.Thread.run(Thread.java:724)引起:   java.lang.ClassCastException:javax.faces.event.ValueChangeEvent   无法转换为javax.faces.event.AjaxBehaviorEvent at   org.primefaces.component.tree.Tree.queueEvent(Tree.java:308)at at   javax.faces.component.UIComponentBase.queueEvent(UIComponentBase.java:1057)     在   javax.faces.component.UIComponentBase.queueEvent(UIComponentBase.java:1057)     在   javax.faces.component.UIComponentBase.queueEvent(UIComponentBase.java:1057)     在javax.faces.component.UIInput.validate(UIInput.java:992)at   javax.faces.component.UIInput.executeValidate(UIInput.java:1249)at at   javax.faces.component.UIInput.processValidators(UIInput.java:712)at at   javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)     在   org.primefaces.component.inplace.Inplace.processValidators(Inplace.java:218)     在   org.primefaces.component.api.UITree.processColumnChildren(UITree.java:442)     在org.primefaces.component.api.UITree.processNode(UITree.java:372)     在org.primefaces.component.api.UITree.processNode(UITree.java:380)     在org.primefaces.component.api.UITree.processNodes(UITree.java:365)     在   org.primefaces.component.api.UITree.processValidators(UITree.java:308)     在   org.primefaces.component.tree.Tree.processValidators(Tree.java:377)     在   com.sun.faces.context.PartialViewContextImpl $ PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:552)     在   com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)     在org.primefaces.component.api.UITree.visitTree(UITree.java:552)at   javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)at at   javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)at at   javax.faces.component.UIForm.visitTree(UIForm.java:371)at   javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)at at   javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)at at   com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:399)     在   com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:263)     ...... 28

1 个答案:

答案 0 :(得分:1)

适用于Mojarra 2.0.3(FCS b03),PrimeFaces 4.0。

请告诉我们您使用的版本的更多信息,并提供您的支持bean的onDragDrop方法的确切代码。我猜这与你的方法没有使用正确的参数类型有关( TreeDragDropEvent 是预期的,而不是 ValueChangeEvent )。

应该是这样的:

public void onDragDrop(TreeDragDropEvent event) { 
  ...
}