• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Using DispatchAction ,error whe nusing request scope

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
sudhakar Tadepalli
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think If I extend action class to Action and have individual action classes, this should work right?

Thanks
Sudhakar
 
sudhakar Tadepalli
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marc, Any Idea how to fix the problem to set collection in the formBean ?

Sudhakar
 
sudhakar Tadepalli
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic