DragAndDrop example error eventBean.processDrop NullPointerException
valatharv Jul 26, 2011 11:11 AMHi,
I am trying to run simple DragAndDrop example from Richfaces AS-IS. It is giving following exception during EventBean.processDrop...
Environment : jboss-4.2.3, jboss-seam-2.0.2.SP1, richfaces 3.3.3.Final
Please suggest, is it related to any configuration issue.... or what is wrong..
Here is error log, xhtml, DnDBean, EventBean and web.xml
Regards
Log :
[javax.enterprise.resource.webcontainer.jsf.lifecycle] JSF1054: (Phase ID: INVOKE_APPLICATION 5, View ID: /TestDragDrop.xhtml) Exception thrown during phase execution: javax.faces.event.PhaseEvent[source=com.sun.faces.lifecycle.LifecycleImpl@14dec09]
[org.jboss.seam.web.ExceptionFilter] handling uncaught exception
javax.servlet.ServletException: /TestDragDrop.xhtml @65,86 dropListener="#{eventBean.processDrop}": java.lang.NullPointerException
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
...
Caused by: javax.faces.el.EvaluationException: /TestDragDrop.xhtml @65,86 dropListener="#{eventBean.processDrop}": java.lang.NullPointerException
at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:73)
at org.richfaces.component.UIDropSupport.broadcast(UIDropSupport.java:63)
at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:184)
...
Caused by: java.lang.NullPointerException
at com.test.session.EventBean.processDrop(EventBean.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
package com.test.session;
import java.util.ArrayList;
import java.util.List;
import org.jboss.seam.annotations.Name;
import org.richfaces.component.Dropzone;
import org.richfaces.event.DragEvent;
import org.richfaces.event.DropEvent;
@Name("dndBean")
public class DnDBean {
public static final String DRAGLISTENER = "DragListener,";
public static final String DROPLISTENER = "DropListener,";
public static final String RICHDROPLISTENER = "RichDropListener,";
public static final String RICHDRAGLISTENER = "RichDragListener,";
private List<Framework> containerPHP;
private List<Framework> containerCF;
private List<Framework> containerDNET;
private List<Framework> frameworks;
private String status = "";
private Object dropValue;
private Object dragValue;
private Boolean rendered;
public DnDBean() {
initList();
}
public List<Framework> getContainerPHP() {
return containerPHP;
}
public List<Framework> getContainerCF() {
return containerCF;
}
public List<Framework> getContainerDNET() {
return containerDNET;
}
public List<Framework> getFrameworks() {
return frameworks;
}
public void moveFramework(Object fm, Object family) {
List<Framework> target = null;
if ("PHP".equals(family)) {
target = containerPHP;
} else if ("DNET".equals(family)) {
target = containerDNET;
} else if ("CF".equals(family)) {
target = containerCF;
}
if (null != target && frameworks.contains(fm)) {
System.out.println("DnDBean.moveFramework, 3");
target.add((Framework) fm);
frameworks.remove(fm);
}
}
public String reset() {
status = "";
dropValue = null;
dragValue = null;
rendered = true;
initList();
return null;
}
public String testRendered() {
rendered = false;
return null;
}
private void initList() {
frameworks = new ArrayList<Framework>();
frameworks.add(new Framework("Flexible Ajax", "PHP"));
frameworks.add(new Framework("ajaxCFC", "CF"));
frameworks.add(new Framework("AJAXEngine", "DNET"));
frameworks.add(new Framework("AjaxAC", "PHP"));
frameworks.add(new Framework("MonoRail", "DNET"));
frameworks.add(new Framework("wddxAjax", "CF"));
frameworks.add(new Framework("AJAX AGENT", "PHP"));
frameworks.add(new Framework("FastPage", "DNET"));
frameworks.add(new Framework("JSMX", "CF"));
frameworks.add(new Framework("PAJAJ", "PHP"));
frameworks.add(new Framework("Symfony", "PHP"));
frameworks.add(new Framework("PowerWEB", "DNET"));
containerPHP = new ArrayList<Framework>();
containerCF = new ArrayList<Framework>();
containerDNET = new ArrayList<Framework>();
}
public void processDropMethod(DropEvent event) {
Dropzone dropzone = (Dropzone) event.getComponent();
moveFramework(event.getDragValue(), dropzone.getDropValue());
status += DROPLISTENER;
}
public void processDragMethod(DragEvent event) {
event.getAcceptedTypes();
status += DRAGLISTENER;
dragValue = event.getDragValue();
dropValue = event.getDropValue();
}
/**
* Framework
*/
public static class Framework {
private String name;
private String family;
public Framework(String name, String family) {
super();
this.name = name;
this.family = family;
}
public String getFamily() {
return family;
}
public void setFamily(String family) {
this.family = family;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
/**
* @return the status
*/
public String getStatus() {
return status;
}
/**
* @param status the status to set
*/
public void setStatus(String status) {
this.status = status;
}
/**
* @return the dropValue
*/
public Object getDropValue() {
return dropValue;
}
/**
* @param dropValue the dropValue to set
*/
public void setDropValue(Object dropValue) {
this.dropValue = dropValue;
}
/**
* @return the dragValue
*/
public Object getDragValue() {
return dragValue;
}
/**
* @param dragValue the dragValue to set
*/
public void setDragValue(Object dragValue) {
this.dragValue = dragValue;
}
public Boolean getRendered() {
return rendered;
}
public void setRendered(Boolean rendered) {
this.rendered = rendered;
}
}
import org.jboss.seam.annotations.Name;
import org.richfaces.component.Dropzone;
import org.richfaces.event.DropEvent;
import org.richfaces.event.DropListener;
@Name("eventBean")
public class EventBean implements DropListener {
private com.test.session.DnDBean dndBean;
public void processDrop(DropEvent dropEvent) {
System.out.println("event happened");
Dropzone dropzone = (Dropzone) dropEvent.getComponent();
dndBean.moveFramework(dropEvent.getDragValue(), dropzone.getDropValue());
}
public com.test.session.DnDBean getDndBean() {
return dndBean;
}
public void setDndBean(com.test.session.DnDBean dndBean) {
System.out.println("bean get invoked");
this.dndBean = dndBean;
}
}
<?xml version="1.0" ?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <!-- Ajax4jsf --> <context-param> <param-name>org.richfaces.SKIN</param-name> <param-value>blueSky</param-value> </context-param> <!-- Seam --> <listener> <listener-class>org.jboss.seam.servlet.SeamListener</listener-class> </listener> <filter> <filter-name>Seam Filter</filter-name> <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class> </filter> <filter-mapping> <filter-name>Seam Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <servlet-name>Seam Resource Servlet</servlet-name> <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>Seam Resource Servlet</servlet-name> <url-pattern>/seam/resource/*</url-pattern> </servlet-mapping> <!-- Facelets development mode (disable in production) --> <context-param> <param-name>facelets.DEVELOPMENT</param-name> <param-value>true</param-value> </context-param> <!-- JSF --> <context-param> <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>javax.faces.DEFAULT_SUFFIX</param-name> <param-value>.xhtml</param-value> </context-param> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.seam</url-pattern> </servlet-mapping> <security-constraint> <display-name>Restrict raw XHTML Documents</display-name> <web-resource-collection> <web-resource-name>XHTML</web-resource-name> <url-pattern>*.xhtml</url-pattern> </web-resource-collection> <auth-constraint/> </security-constraint> </web-app>