Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring-mvc 3.0 crud with checkboxes issue
    text
    copied!<p>I am doing an simple user crud.</p> <p>My <code>ApplicationUser</code> has the following properties:</p> <pre><code>private Long id; private String password; private String username; private Collection&lt;Authority&gt; myAuthorities; private boolean isAccountNonExpired; private boolean isAccountNonLocked; private boolean isCredentialsNonExpired; private boolean isEnabled; </code></pre> <p>Authority class has:</p> <pre><code>private Long id; private String authority; private String name; </code></pre> <p>In my jsp, my view has the following form:</p> <pre><code>&lt;form:form modelAttribute="applicationUser" action="add" method="post"&gt; &lt;fieldset&gt; &lt;form:hidden path="id" /&gt; &lt;legend&gt;&lt;fmt:message key="user.form.legend" /&gt;&lt;/legend&gt; &lt;p&gt;&lt;form:label for="username" path="username" cssErrorClass="error"&gt;&lt;fmt:message key="user.form.username" /&gt;&lt;/form:label&gt;&lt;br /&gt; &lt;form:input path="username" /&gt; &lt;form:errors path="username" /&gt;&lt;/p&gt; &lt;p&gt;&lt;form:label for="password" path="password" cssErrorClass="error"&gt;&lt;fmt:message key="user.form.password" /&gt;&lt;/form:label&gt;&lt;br /&gt; &lt;form:password path="password" /&gt; &lt;form:errors path="password" /&gt;&lt;/p&gt; &lt;p&gt;&lt;form:label for="password" path="password" cssErrorClass="error"&gt;&lt;fmt:message key="user.form.password2" /&gt;&lt;/form:label&gt;&lt;br /&gt; &lt;form:password path="password" /&gt; &lt;form:errors path="password" /&gt;&lt;/p&gt; &lt;p&gt;&lt;form:label for="myAuthorities" path="myAuthorities" cssErrorClass="error"&gt;&lt;fmt:message key="user.form.autorities" /&gt;&lt;/form:label&gt;&lt;br /&gt; &lt;form:checkboxes items="${allAuthorities}" path="myAuthorities" itemLabel="name"/&gt;&lt;form:errors path="myAuthorities" /&gt;&lt;/p&gt; &lt;p&gt;&lt;input type="submit"/&gt;&lt;/p&gt; &lt;/fieldset&gt; &lt;/form:form&gt; </code></pre> <p>The jsp gets <code>allAuthorities</code> from this:</p> <pre><code>@ModelAttribute("allAuthorities") public List&lt;Authority&gt; populateAuthorities() { return authorityService.findAll(); } </code></pre> <p>When I fill the form I get:</p> <blockquote> <p>Failed to convert property value of type java.lang.String to required type java.util.Collection for property myAuthorities; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.tda.model.applicationuser.Authority] for property myAuthorities[0]: no matching editors or conversion strategy found</p> </blockquote> <p>Which is the correct way to solve this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload