spring MVC : form : radiobutton for Boolean property
23,764
Solution 1
I have them working on my form like this:
<form:radiobutton path="someProperty" value="true"/>
<spring:message code="label.roundYes"/>
<form:radiobutton path="someProperty" value="false"/>
<spring:message code="label.roundNo"/>
and in my model object the someProperty looks like this:
private boolean someProperty = false;
That works fine. I haven't tried it with 'Boolean'. Maybe just try it with boolean and see if it helps.
Solution 2
Just to clarify things: In my opinion it also works with Boolean Object. I have a form using Spring 3 and this setup is running perfect (using true/false/null Values as an Option):
Form JSP:
<form:radiobutton path="tour.routeNachZeit" value="true" />
<form:radiobutton path="tour.routeNachZeit" value="false" />
Model Object (named Tour):
private Boolean routeNachZeit;
Therefore I don't unterstand why I should have changed my Property to simple boolean. This works in my case.
My help came from this post in the Spring Forum.
Related videos on Youtube
Author by
BasicCoder
Updated on May 20, 2020Comments
-
BasicCoder over 3 years
I just want to know how to use a Boolean in a Spring mvc form.
I try with this code:
My jsp:
<form:radiobutton path="dateInterval" value="false" cssClass="radio"/> <form:radiobutton path="dateInterval" value="true" cssClass="radio"/>
The property on the pojo:
private Boolean dateInterval = false;
But my dateInterval property is always null!
-
DwB over 12 yearsA common mistake is to use isBlah for the property Boolean blah; This is wrong. isBlah will only work for type boolean. Use getBlah for Boolean blah;
-
-
BasicCoder over 12 yearsyes, you right, it works! Sorry for this stupid question! Works perfectly with a boolean and not Boolean. Thank you.
-
Anthony Hayward almost 8 yearsBoolean is useful when you don't want true or false to be selected initially. This answer doesn't asnwer the question.