GeeCON Prague 2014*
The moose likes Struts and the fly likes Using DispatchAction ,error whe nusing request scope Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Using DispatchAction ,error whe nusing request scope" Watch "Using DispatchAction ,error whe nusing request scope" New topic
Author

Using DispatchAction ,error whe nusing request scope

sudhakar Tadepalli
Ranch Hand

Joined: Dec 27, 2001
Posts: 130
I am using DispatchAction and defined all the methods in one actiona class.
list,edit,editSubmit. Intially I put my form bean in session everything wroks fine. Now I changed to scope="request", I got the list page when I selected checkbox and click edit. I am getting nullpointer exception.Submit action did not even calling Action class.

I added few lines in my list jsp to get request and setrequest
LifeAFormBean jspForm = (LifeAFormBean)request.getAttribute("dataForm");
request.setAttribute("dataForm", jspForm);

Still same error.Some times It is shoing
CDT] 55225522 DispatchActio E org.apache.struts.actions.DispatchAction Request[/edit] does not contain handler parameter named method

Strus-config.xml
<action path="/data" type="com.web.actions.LifeAAction"
name="dataForm" scope="request" parameter="method" validate="false" >
<forward name="list" path="page.lifeA" />

</action>

<action path="/edit" type="com.web.actions.LifeAAction"
name="dataForm" scope="request" parameter="method" validate="true" input="page.lifeA">
<forward name="edit" path="page.edit" />
</action>

<action path="/editsubmit" type="com.web.actions.LifeAAction"
name="dataForm" scope="request" parameter="method" validate="true" input="page.edit">
<forward name="success" path="page.success" />
</action>

I changed it back to session everthing works fine.Can some one point me wheer I am doing wrong with request?

Thanks
Sudhakar
sudhakar Tadepalli
Ranch Hand

Joined: Dec 27, 2001
Posts: 130
I was not eve able to debug as it never goes to The Action class.Here is the log

[8/19/05 15:36:18:265 CDT] 62056205 WebGroup E SRVE0026E: [Servlet Error]-[BeanUtils.populate]: java.lang.NullPointerException
at java.lang.Throwable.<init>(Throwable.java)
at java.lang.Throwable.<init>(Throwable.java)
at java.lang.NullPointerException.<init>(NullPointerException.java:61)
at org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:515)
at org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:428)
at org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.java:770)
at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:801)
at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java)
at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java)
at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1252)
at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:821)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:1171)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:203)

Sudhakar
Srilakshmi Vara
Ranch Hand

Joined: Jul 21, 2004
Posts: 169
Hi sudhakar,

Check all the variables you are using in the jsp when you set the form in the request scope every time you submit the form, it does not store any state of the form in between the actions, if you want like that then you need to put the form in session scope, or after every action in the jsp you need to manually set the form object values.

Coming to your error, Struts is not getting the values to populate a form element, just check your population variables of your form.

I think this will help you in debugging.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

You have an array or collection in the ActionForm that gets initialized to null. When Struts tries to set indexed properties to it you get the NPE because it cannot find the array or collection to in which place the values.


A good workman is known by his tools.
sudhakar Tadepalli
Ranch Hand

Joined: Dec 27, 2001
Posts: 130
Srilakshmi,
Thanks for your reply, I am getting the form from the request and setting the hole object to request again.
In list.jsp I am doing this, so when I select one and click edit button I am assuming the request object sends the form bean to the the action again.

LifeAFormBean jspForm = (LifeAFormBean)request.getAttribute("dataForm");
request.setAttribute("dataForm", jspForm);

Sudhakar
sudhakar Tadepalli
Ranch Hand

Joined: Dec 27, 2001
Posts: 130
I think If I extend action class to Action and have individual action classes, this should work right?

Thanks
Sudhakar
sudhakar Tadepalli
Ranch Hand

Joined: Dec 27, 2001
Posts: 130
Marc, You may be right too, As I am extending action calss to DispatchAction, even I try to get the form from request, the form was initialized. I am not even able to debug as it is not even coming to action class.

public ActionForward list(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
LifeAFormBean jspForm = (LifeAFormBean) form;
ArrayList collection = new ArrayList();
log.debug("entering DataManager ...");
ArrayList list = (ArrayList) mgr.searchData();
log.debug("entering DataManager ..2222.");
for (int i = 0; i < list.size(); i++) {
LifeAFormBean bean = new LifeAFormBean();
Data data = (Data) list.get(i);
bean.setName(data.getName());
bean.setNodeid(data.getNodeid());
bean.setPersonid(data.getPersonid());
bean.setSceneid(data.getSceneid());

bean.setValue(data.getValue());
collection.add(bean);

}

jspForm.setCollection(collection);

//request.setAttribute("dataForm", jspForm);

return mapping.findForward("list");
}

public ActionForward edit(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {

LifeAFormBean jspForm = (LifeAFormBean)request.getAttribute("dataForm");


for (int i = 0; i < jspForm.getCollection().size(); i++) {
if(jspForm.getProductInfo(i).getSelectId() != null){

jspForm.setName(jspForm.getProductInfo(i).getName());
jspForm.setNodeid(jspForm.getProductInfo(i).getNodeid());
jspForm.setPersonid(jspForm.getProductInfo(i).getPersonid());
jspForm.setSceneid(jspForm.getProductInfo(i).getSceneid());
jspForm.setValue(jspForm.getProductInfo(i).getValue());
}
}
jspForm.reset(mapping, request);
return mapping.findForward("edit");
sudhakar Tadepalli
Ranch Hand

Joined: Dec 27, 2001
Posts: 130
Marc, Any Idea how to fix the problem to set collection in the formBean ?

Sudhakar
sudhakar Tadepalli
Ranch Hand

Joined: Dec 27, 2001
Posts: 130
Never Mind, I solved the problem.Marc, You are right. It is problem with seetting collection back in to request object. I break the form into parent child and used those forms according to the actionPath(I just moved my collection part to another form)

Thanks
Sudhakar
 
GeeCON Prague 2014
 
subject: Using DispatchAction ,error whe nusing request scope