I have a JSP with multiple forms as the "edit" view of a开发者_运维知识库n 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?
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:
- lacking a reset() method to treat checkboxes - from your question, it seems unlikely to be this;
- having a form with "request" scope used for chained page calls - again, unlikely to be this;
- 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.
精彩评论