I have a boolean attribute in one of my classes that appears web form as a radio group. I'm using MySQL as the database so the value is store as a
BIT but when the form is displayed the value displayed in
the form is either true or false. The code for my form is as follows:
<spring:bind path="conditionType.manditory">
<label><input type="radio" name="manditory" value="false" <c:if test="${conditionType.manditory == status.value}">checked="checked"</c:if> />False</label>
<label><input type="radio" name="manditory" value="true" <c:if test="${conditionType.manditory == status.value}">checked="checked"</c:if> />True</label>
<span class="fieldError"><c:out value="${status.errorMessage}"/></span>
</spring:bind>
This populates the webForm correctly but when I try to edit this value... by replacing true with
false or visa versa then try to save the form the error message
Cannot convert property value of type [java.lang.String] to
required type [java.lang.Boolean] for property 'manditory'
I have read through the documentation but I think I must be doing something incorrectly because I'm still getting the same error. Can anyone point me in the right direction or point out where Im going wrong... I've over written the onBind method for my Controller class to what is below. Any ideas?
protected void onBind(HttpServletRequest request,Object command, BindException errors)
throws java.lang.Exception {
ConditionType conditionType = (ConditionType) command;
String value = request.getParameter("manditory");
if ( value.trim().equalsIgnoreCase(TRUE) ) {
conditionType.setManditory(Boolean.TRUE);
}
else {
conditionType.setManditory(Boolean.FALSE);
}
}


Reply With Quote