Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using indexId

 
harsha madiraju
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


  • [*
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic