Spring form errors with multiple identical forms on the same page -
i printing arbitrary number of identical forms on page using spring's <form:form
tag, , need way distinguish between them, because form errors of 1 form printed on forms.
currently identical forms bound same, single backing object. works fine, because user can submit 1 form @ time.
i using spring validation validate form fields. when 1 of fields has error (let's 'name' empty) error message printed under 'name' field of forms.
obviously, need way allow spring distinguish between forms, how?
some example code:
this spring webflow definition creates clientformbacking object client forms. , submits form post bindandvalidate method, calls validator.
<webflow:var name="clientformbacking" class="com.example.clientformbacking"/> <webflow:view-state id="list" view="clients" model="clientformbacking"> <webflow:on-entry> <webflow:evaluate expression="contextparametermanager.findall()" result="flowscope.clients"/> </webflow:on-entry> <webflow:transition on="update-client" to="list"> <webflow:evaluate expression="clientbinder.bindandvalidate(flowrequestcontext)"/> <webflow:evaluate expression="clientservice.saveorupdate(flowscope.clientspagebacking)"/> </webflow:transition> </webflow:view-state>
print arbitrary number of identical forms name field , name error field in jsp:
<c:foreach items="${clients} var="client"> <form:form commandname="clientformbacking"> <form:input path='name' value='${client.name}'/> <form:errors path="name" cssclass="input-error" /> </form:form> </c:foreach>
the validator rejects 'name' field:
clientvalidator implements validator { public void validate(object target, errors errors) { // problem here! there multiple <form:errors path='name'/> tags.... errors.rejectvalue("name", "validation.error.name.empty"); } }
Comments
Post a Comment