Reputation: 3494
How can I prevent a form bean field from being reset when submitted for validation. The thing here is, this form field is not a input field on the jsp. It is shown as normal html textlike this..
<div class="label">
<fmt:message bundle="${labels}" key="gender" />
</div>
<div class="data">
<bean:write property="gender" name="infoForm"/>
</div>
What is happening is that, when I click submit button and if there are any validation errors, all other input fields are populated again but this one gender field is not shown.
My guess is since the gender property here is not an input field, when the form is reset before or after validation, gender value is not populated. Am I correct? If so, what can I do to not reset this one particular field?
Upvotes: 0
Views: 2312
Reputation: 3494
To solve this issue, I have added a hidden form field with same parameter...
<html:hidden property="gender" name="infoForm"/>
that retained the field value after reset in validation...
Upvotes: 0
Reputation: 692081
If this information comes from a form in a previous page (for example if you're implementing a wizard, where a single big form is splitted into several pages), then you could use a form hidden field to store the information and resubmit it in every subsequent form.
If this is just information coming from the server (from the database, for example, or computed from other input fields), then you should simply get the information again from the database (or recompute it) and put it again in the form.
Upvotes: 1