You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Musachy Barroso (JIRA)" <ji...@apache.org> on 2008/07/21 04:19:05 UTC

[jira] Resolved: (WW-2513) EnumMap's not supported in type conversion + InstantiationException

     [ https://issues.apache.org/struts/browse/WW-2513?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Musachy Barroso resolved WW-2513.
---------------------------------

    Resolution: Fixed

This now works. The action:

public class UITagExample {
....
private EnumMap<Test, String> enumMap;

   @Element(String.class)
   @Key(Test.class)
    public void setEnumMap(EnumMap<Test, String> map) {
       this.enumMap = map;
    }

}

The enum:

public enum Test {
  A, B
}

The jsp submitting the form:

<s:form action="exampleSubmit" >
    <input type="hidden" name="enumMap[@org.apache.struts2.showcase.Test@A]" value="test1" />
</s:form>

The jsp printing it:

 <s:label label="Emap" name="enumMap[@org.apache.struts2.showcase.Test@A]" />

> EnumMap's not supported in type conversion + InstantiationException
> -------------------------------------------------------------------
>
>                 Key: WW-2513
>                 URL: https://issues.apache.org/struts/browse/WW-2513
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Plugin - Tags
>    Affects Versions: 2.0.11
>         Environment: Windows 2000 SP4
> WebLogic Server 9.2 M1
> JVM 5.0 (build 1.5.0_06-b05) - bundled with WLS installation
>            Reporter: Maxx
>             Fix For: 2.1.3
>
>         Attachments: struts.xml, test.jsp, TestAction-conversion.properties, TestAction.java, TestEnum.java
>
>
> Unlike regular classes implementing interface java.util.Map, EnumMap are not well supported through the (automatic?) "Type Conversion" as described here: http://struts.apache.org/2.x/docs/type-conversion.html
> 1/ the values can't be retrieved through the use of some map-like OGNL expressions like %{myEnumMap['myEnumValue']}
> Neither by just removing the single quotes i.e. %{myEnumMap[myEnumValue]} or by using the @...@ notation e.g. %{myEnumMap[@com.mycompany.somepackage.business@MyEnum.myEnumValue]} it still doesn't work.
> In the example below, the corresponding <s:textfield /> are not populated, while the ones for the Map are.
> 2/ when setting values back to the object, an InstantiationException occurs.
> Effectively, an EnumMap has NO no-arg constructor because initializing an Enum needs to set a parameter: the enum type.
> Note: IMHO looking for a declared no-arg constructor is wrong as Java automatically declares a public no-arg constructor, but here it's not exactly the problem (I'll come back later to this with another issue).
> See attached files for a full running example:
> - TestAction.java:
>  * 1 Map & 1 EnumMap are initialized with 2 entries (key+value) both
>  * the execute() method does the initialization, while the executeLog() does the logging.
> - TestAction-conversion.properties: the appropriate type conversion properties file
> - TestEnum.java: the Enum used as key universe for the EnumMap
> - test.jsp: contains too iterators over the Map & the EnumMap
> - struts.xml (but it's succinct)
> Note: the conversion settings for the testMap seem not to be mandatory as setting back the values into the action without them works fine.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.