spring mvc - JSP int values are casted to bool -


i'm working on project in jsp , have problem generated html.

generated html: "1" transformed "oui" (yes in french) , "0" "non" (no in french)

<select id="privilegesrole" name="privileges" multiple="multiple">     <option value="5" selected="selected">role 1</option>     <option value="4" selected="selected">role 2</option>     <option value="oui" selected="selected">role 3</option>     <option value="6" selected="selected">role 4</option>     <option value="2" selected="selected">role 5</option>     <option value="non" selected="selected">role 6</option>     <option value="3" selected="selected">role 7</option> </select> 

my jsp code:

<form:select path="privileges" multiple="true" id="privilegesrole">     <form:options itemlabel="libelle" itemvalue="id" items="${role.privileges}" /> </form:select> 

controller: in controller values good

roleadministration role = findby....(); model.addattribute("role", role); 

thank in advance help

edit: have booleanformatter.java not see used

import org.springframework.format.formatter; import org.springframework.stereotype.component;  @component public class booleanformatter implements formatter<boolean> {     private string truelabel = utilmessages.getinstance().getstring("common.oui");     private string falselabel = utilmessages.getinstance().getstring("common.non");     @override    public string print(boolean arg0, locale arg1) {        return arg0 ? truelabel : falselabel;    }     @override    public boolean parse(string arg0, locale arg1) throws parseexception {        if (boolean.true.tostring().equals(arg0))            return true;        else if (boolean.false.tostring().equals(arg0)) {            return false;        } else if (truelabel.equals(arg0))            return true;        else if (falselabel.equals(arg0)) {            return false;        }        throw new parseexception(arg0, 0);    } } 

we have changed jsp code to:

<form:select id="privilegesrole" path="privileges" multiple="true" >     <c:foreach items="${role.privileges}" var="currprivilegeselect">         <option value="<c:out value="${currprivilegeselect.id}"/>"                  title="<c:out value="${currprivilegeselect.description}"/>">                  <c:out value="${currprivilegeselect.libelle}"/> </option>     </c:foreach> </form:select> 

and works, don't know why. if have explication happy read :)

check privileges object inside roleadministration, field id, according spring formatter documentation can associate field either annotation formatted or implement custom format annotation. in case can like

@formatted(booleanformatter.class) or @booleanformatted

both on top of field id inside privileges object.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -