Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding spring:checkboxes to enumset on submit causes error
    primarykey
    data
    text
    <p>Just a heads up, I am using Java and Spring for a web app.</p> <p>I have an object (objectBean) that contains an EnumSet (enumSet) of type EnumInnerObject as an attribute. I am passing this object as a bean from my controller to my .jsp view. I use the following .jsp code to bind the checkboxes:</p> <pre><code>&lt;form:form commandName="objectBean" name="whatever" action="./save.htm" method="post"&gt; &lt;form:checkboxes items="${allOptions}" path="enumSet" /&gt; &lt;/form:form&gt; </code></pre> <p>Here is my controller initbinder:</p> <pre><code>@InitBinder protected void initBinder(WebDataBinder binder) throws Exception{ binder.registerCustomEditor(EnumSet.class, "enumSet", new CustomCollectionEditor(Collection.class){ protected Object convertElement(Object element){ if(element instanceof String){ EnumInnerObject enumInnerObject= EnumInnerObject.valueOf((String)element); return enumInnerObject; } return null; } }); </code></pre> <p>In the controller, I pass allOptions (separate from my bean), and this contains all EnumInnerObject options, so all the checkboxes are displayed. "enumSet" is the EnumSet attribute with the appropriate values contained (if the value is contained in EnumSet, then it automatically checks the correct box in "allOptions"). All of this works and the .jsp correctly shows the correct checked boxes. However, the problem is when I submit the page to save. I get the following error:</p> <pre><code>java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String[]] to required type [java.util.EnumSet] for property 'enumSet': PropertyEditor [com.example.controller.MyController$1] returned inappropriate value] </code></pre> <p>I have a feeling I have to modify the InitBinder to get the form submit to work. Any ideas??</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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