• Post Reply Bookmark Topic Watch Topic
  • New Topic

using indexId  RSS feed

harsha madiraju
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

root cause

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
    Boost this thread!