views:

29

answers:

1

I have a JSP with multiple forms as the "edit" view of an object. Now I want to send one of the forms, but there is an error in the validate method, because one of the input fields was not filled.

When the bean is validate and the error is found, Struts returns to the JSP which is defined as the INPUT for the bean in my struts-config.xml. But now the other forms are missing their values.

How can I solve this issue, so I'll be returns to the JSP with all forms filled again?

+1  A: 

When Struts receives the parameters from your submitted form, it binds them to the ActionForm object and then calls validate() on the ActionForm object. The binded parameters remain there when you return to the page and you should have your values present in the page.

There are some things that can interfere with this mechanism:

  1. lacking a reset() method to treat checkboxes - from your question, it seems unlikely to be this;
  2. having a form with "request" scope used for chained page calls - again, unlikely to be this;
  3. The most probable cause - you have multiple forms in the page but you only submit one of them so the fields in the other forms are not sent to the server. As a result, Struts has nothing to bind for them. When you return to the page you have your values missing. This is not a Struts problem. You can solve this by having all fields in one form or use JS to also submit the fields from the other forms to. See a similar issue here.
dpb
Right, the 3. is my problem. I already started integration all the forms in one bean. Do I have to use some kind of "action" property then to figure out which action I want to do or do I assign the new all-knowing-bean to my different actions with struts-config.xml?
cringe
The solution you choose depends on your application. Choose the easiest and more manageable solution now that you know where the issue is. Regarding the “action” property, I guess you could go for using an org.apache.struts.actions.LookupDispatchAction or org.apache.struts.actions.DispatchAction to manage it, if that does not bring to much overhead into your app.
dpb