• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

using indexId

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


  • [*
    reply
      Bookmark Topic Watch Topic
    • New Topic