validate valid starter mvc example español body bean java json spring spring-mvc jsr

java - starter - La anotación JSR-303 @Valid(objeto anidado) no funciona



spring mvc español (2)

Al agregar a la respuesta @Ritesh, la restricción @Valid indicará al Bean Validator que profundice en el tipo de su propiedad aplicada y valide todas las restricciones encontradas allí. Responda con un código a su pregunta, el validador, al ver una restricción @Valid en la propiedad de addresses , explorará la clase AddressForm y validará todas las restricciones JSR 303 que se encuentran en el interior, de la siguiente manera:

public class UserAddressesForm { @NotEmpty private String firstName; @NotEmpty private String lastName; @Valid private List<AddressForm> addresses; ... setters and getters public class AddressForm { @NotEmpty private String customName; @NotEmpty private String city; @NotEmpty private String streetAn; @NotEmpty private String streetHn; @NotEmpty private String addressCountry; @NotEmpty private String postCode; ... setters and getters

[primavera 3.0.5] [Jboss 5.1]

Mis clases principales son

public class UserAddressesForm { @NotEmpty private String firstName; @NotEmpty private String lastName; private List<AddressForm> addresses; ... setters and getters public class AddressForm { @NotEmpty private String customName; @NotEmpty private String city; @NotEmpty private String streetAn; @NotEmpty private String streetHn; @NotEmpty private String addressCountry; @NotEmpty private String postCode; ... setters and getters

Un controlador

@RequestMapping(value = "/up", method = RequestMethod.POST) public String completeForm(@Valid @ModelAttribute("userAddressesForm") UserAddressesForm userAddressesForm, BindingResult result, HttpServletRequest req) ...

Una página JSP

<form:form commandName="userAddressesForm" action="registered"> <table> <tr> <td class="formLabels"><form:label path="firstName"> <spring:message code="label.name" /> </form:label></td> <td><form:input path="firstName" /></td> <td><form:errors path="firstName" cssClass="error" /></td> </tr> <tr> <td class="formLabels"><form:label path="lastName"> <spring:message code="label.surname" /> </form:label></td> <td><form:input path="lastName" /></td> <td><form:errors path="lastName" cssClass="error" /></td> </tr> </table> <c:forEach items="${userAddressesForm.addresses}" varStatus="gridRow"> <div id="main_address" class="address_data_form"> <fieldset> <legend><spring:message code="label.stepThreeMainAddressInfo" /></legend> <a href="#" class="deleteItem"></a> <table> <tr> <td class="formLabels"> <spring:message code="label.address.custom.name" /> </td> <td> <spring:bind path="addresses[${gridRow.index}].customName"> <input type="input" name="<c:out value="${status.expression}"/>" id="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>" /> <form:errors path="${status.expression}"/> </spring:bind> </td> </tr> <tr> <td class="formLabels"> <spring:message code="label.streetAnStreetHn" /> </td> <td> <spring:bind path="addresses[${gridRow.index}].streetAn"> <input type="input" name="<c:out value="${status.expression}"/>" id="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>" /> </spring:bind> <spring:bind path="addresses[${gridRow.index}].streetHn"> <input type="input" name="<c:out value="${status.expression}"/>" id="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>" > <form:errors path="addresses[${gridRow.index}].streetHn"/> </spring:bind> </td> </tr> <tr> <td class="formLabels"> <spring:message code="label.postCode" /> </td> <td> <spring:bind path="addresses[${gridRow.index}].postCode"> <input type="input" name="<c:out value="${status.expression}"/>" id="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>" /> </spring:bind> </td> </tr> <tr> <td class="formLabels"> <spring:message code="label.city" /> </td> <td> <spring:bind path="addresses[${gridRow.index}].city"> <input type="input" name="<c:out value="${status.expression}"/>" id="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>" /> <form:errors path="addresses[${gridRow.index}].city" cssClass="error" /> </spring:bind> </td> </tr> </table> </fieldset> </div> </c:forEach>

¿Por qué los campos de objeto no son validados AddressForm?

Por favor ayuda.