wood burning stoves 2.0*
The moose likes Struts and the fly likes using indexId Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "using indexId" Watch "using indexId" New topic
Author

using indexId

harsha madiraju
Greenhorn

Joined: Dec 20, 2004
Posts: 10
Hi,

I am using following JSP

Form bean is as follows

DemoVO has got setters and getters for empName and empId

When I hit my action, the form is displayed with all fields
populated from corresponding properties, but when i submit the
form I get following exception. Please clarify



javax.servlet.ServletException: BeanUtils.populate
org.apache.struts.util.RequestUtils.populate
(RequestUtils.java:1254)
org.apache.struts.action.RequestProcessor.processPop
ulate(RequestProcessor.java:821)
org.apache.struts.action.RequestProcessor.process
(RequestProcessor.java:254)
org.apache.struts.action.ActionServlet.process
(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost
(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service
(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service
(HttpServlet.java:802)


root cause

java.lang.reflect.InvocationTargetException
sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)


<b><i>FACE YOUR FEARS LIVE YOUR DREAMS</i></b>
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You haven't indicated what scope is specified for your ActionForm in struts-config.xml. I suspect it's "request", and that would cause this problem. When a form bean is scoped to request, All the information you created to display the form is gone once the information is sent back to the browser. When the user submits the form, Struts instatiates a new ActionForm, but this one has no ArrayList of Employee objects. That's why you get the error.

The two possible solutions are:
  • Use session scope for the form bean. This is the easiest to implement, but you need to be careful how much data you store in the HTTPSession, as it can negatively impact your performance with many simultaneous users.
  • Keep the ActionForm at request scope and store only the total number of employees in the session. Then, in your ActionForm's reset() method, check to see if the ArrayList of employees is null. If it is, build an ArrayList with the correct number of employees. Then, when the user submits the form, the getters and setters will find the appropriate objects.


  • [*


    Merrill
    Consultant, Sima Solutions
     
    jQuery in Action, 2nd edition
     
    subject: using indexId
     
    Similar Threads
    Nested Iterator Tags
    Dynamic Textboxes.
    Problem with logic:iterate tag
    Trouble with indexed properties
    Set Bean from JSP using Index