Hello everyone.
I have a really annonying problem with a somewhat evident thing : setting a boolean value of a command object from a checkbox.
Here is my code.
Business Class
(note : getters and setters are ok, of course... )Code:public class DemandeDeCatalogue { private boolean optin; private Address address = new Address(); private String codeGestion = DemandeDeCatalogue.UNSPECIFIED_CATALOGUE; public static final String UNSPECIFIED_CATALOGUE = "-1"; ...(snip)
Controller Class
andCode:public class CatalogueDemandeFormController extends BaseFormController { (snip...) public CatalogueDemandeFormController() { setCommandClass(DemandeDeCatalogue.class); } (snip...) protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) { binder.registerCustomEditor( null, "address.dateNaissance", new CustomDateEditor(AddressValidator.dateFormat, true) ); binder.registerCustomEditor( null, "optin", new CustomBooleanEditor(true) ); (snip...) }
jsp form extract
I have and AddressValidator class that perform checks on the nested Address class included in the DemandeDeCatalogue class.Code:<form action="demandeCatalogue.html" method="post" name="demandeCatalogueForm"> <spring:bind path="command.address.civility"> <p><label for="<c:out value="${status.expression}" />">Civilité</label> <input type='radio' name='<c:out value="${status.expression}" />' value="1" <c:if test="${status.value == 1}">checked="checked"</c:if> />Monsieur <input type='radio' name='<c:out value="${status.expression}" />' value="2" <c:if test="${status.value == 2}">checked="checked"</c:if> />Madame <input type='radio' name='<c:out value="${status.expression}" />' value="3" <c:if test="${status.value == 3}">checked="checked"</c:if> />Mademoiselle <input type='radio' name='<c:out value="${status.expression}" />' value="4" <c:if test="${status.value == 4}">checked="checked"</c:if> />Société </p> </spring:bind> <spring:bind path="command.address.dateNaissance"> <p><label for="<c:out value="${status.expression}" />">Date de naissance</label> <input type="text" name="<c:out value="${status.expression}" />" id="<c:out value="${status.expression}" />" value="<c:out value="${status.value}" />" size="10" maxlength="10" /> </p> </spring:bind> <spring:bind path="command.address.diversAdresse"> <p><label for="<c:out value="${status.expression}" />">Divers adresse</label> <input type="text" name="<c:out value="${status.expression}" />" id="<c:out value="${status.expression}" />" value="<c:out value="${status.value}" />" size="30" maxlength="30" /> </p> </spring:bind> <spring:bind path="command.optin"> <input type="checkbox" name="<c:out value="${status.expression}" />" id="<c:out value="${status.expression}" />" <c:if test="${status.value == 'on'}">checked="checked"</c:if> /> </spring:bind> <input type="submit" id="save" name="save" alt="Enregistrer" title="Envoyer" /> </form>
Fact is that, after some tests, that EVERYTHING works fine (validating nested Address fields was easy as a breathe !) BUT the 'optin' fields fails miserably !
I get a
when I check the box.Code:Failed to convert property value of type [java.lang.String] to required type [boolean] for property 'optin'; nested exception is java.lang.IllegalArgumentException: Invalid boolean value [on]
I'm totally helpless... everything run smoothly without any problem, even the Date field (providing I set the CustomDateEditor), but it obviously seems to ignore my BooleanCustomEditor...
Any help would be GREATLY appreciated !
Thanks,
sne.


) BUT the 'optin' fields fails miserably !
Reply With Quote