J'ai développé un formulaire ou l'a validation se fait via le validator :
Et voici le code de ma JSP :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 public class PhoneNumberValidator implements Validator { private final Pattern PHONE_PATTERN = Pattern.compile("[0-9]{10}"); public boolean supports(Class<?> clazz) { return AccountData.class.isAssignableFrom(clazz); } public void validate(Object command, Errors errors) { AccountData accountData = (AccountData) command; validatePhoneNumber(accountData, errors); validateCGV(accountData, errors); } private void validatePhoneNumber(AccountData accountData, Errors errors) { ValidationUtils.rejectIfEmpty(errors, "phoneNumber", "phoneNumber.required", "Phone is required."); if(!PHONE_PATTERN.matcher(accountData.getPhoneNumber()).matches()) errors.rejectValue("phoneNumber", "phoneNumber.wrong", "Phone wrong format."); } private void validateCGV(AccountData accountData, Errors errors) { if(!accountData.isCgv()) errors.rejectValue("cgv", "cgv.required", "CGV is required"); } }
Je ne comprends pas vraiment comment faire pour, via du javascript (ici j'utilise JQuery), valider le formulaire.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 <form:form id="phoneSigninForm" name="phoneSigninForm" method="POST" action="${phoneSigninAction}" commandName="accountData"> <form:label id="#mobile-label" path="phoneNumber"> <spring:message code="phone.title" /> <form:input path="phoneNumber" /> </form:label> <input type="submit" value="OK" /> <br /> <form:errors cssClass="webcare-error-message" path="phoneNumber" /> <br /> <form:label path="cgv"> <form:checkbox path="cgv" /> <spring:message code="cgv.text" /> </form:label> <br /> <form:errors cssClass="webcare-error-message" path="cgv" /> </form:form>
Si vous avez déjà fait ce genre de chose je suis preneur.
Merci beaucoup.
Partager