
|
If you were logged in you would be able to see more operations.
|
|
|
WebWork
Created: 20/Oct/06 06:25 AM
Updated: 07/Nov/06 10:52 AM
|
|
| Component/s: |
None
|
| Affects Version/s: |
2.2.4
|
| Fix Version/s: |
2.2.5
|
|
|
Environment:
|
Java 5, Tomcat 5.5.17
|
|
|
I have a User object with an attribute gender which is a Java 5 enum:
public enum Gender {
MALE, FEMALE
}
When I put the folloing tag definition on a page, the actual user's gender is never selected:
<ww:radio label="Gender" name="user.gender" list="genders" />
where "genders" is an attribute of type Map on my action:
genders = new HashMap<Gender, String>();
genders.put(Gender.MALE, "Male");
genders.put(Gender.FEMALE, "Female");
I debugged webwork code and templates and found that the Gender is compared with String value which will always return false since the nature of Java Enum equals method which uses "==" operation:
public final boolean equals(Object other) {
return this==other;
}
In my case I get the following objects into ListIUBean.contains() method:
obj1: of type Gender (Enum)
obj2: of type String
My idea would be to change radiomao.ftl from:
<#if tag.contains(parameters.nameValue, itemKeyStr)>
checked="checked"<#rt/>
</#if>
to
<#if tag.contains(parameters.nameValue, itemKey)>
checked="checked"<#rt/>
</#if>
If I do so, the proper radio element is selected.
Is there some reason why currently itemKeyStr is used to find checked item instead of itemKey value?
|
|
Description
|
I have a User object with an attribute gender which is a Java 5 enum:
public enum Gender {
MALE, FEMALE
}
When I put the folloing tag definition on a page, the actual user's gender is never selected:
<ww:radio label="Gender" name="user.gender" list="genders" />
where "genders" is an attribute of type Map on my action:
genders = new HashMap<Gender, String>();
genders.put(Gender.MALE, "Male");
genders.put(Gender.FEMALE, "Female");
I debugged webwork code and templates and found that the Gender is compared with String value which will always return false since the nature of Java Enum equals method which uses "==" operation:
public final boolean equals(Object other) {
return this==other;
}
In my case I get the following objects into ListIUBean.contains() method:
obj1: of type Gender (Enum)
obj2: of type String
My idea would be to change radiomao.ftl from:
<#if tag.contains(parameters.nameValue, itemKeyStr)>
checked="checked"<#rt/>
</#if>
to
<#if tag.contains(parameters.nameValue, itemKey)>
checked="checked"<#rt/>
</#if>
If I do so, the proper radio element is selected.
Is there some reason why currently itemKeyStr is used to find checked item instead of itemKey value? |
Show » |
|