History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: WW-1369
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: tm_jee
Reporter: Vlad Kravchenko
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
WebWork

Java 5 Enum values are not handled properly by Radio jsp tag

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


 Description  « Hide
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?

 All   Comments   Change History      Sort Order:

tm_jee - [07/Nov/06 10:52 AM ]
fixed changes at

Checking in java/template/simple/radiomap.ftl;
/cvs/webwork/src/java/template/simple/radiomap.ftl,v <-- radiomap.ftl
new revision: 1.11; previous revision: 1.10
done
Checking in test/com/opensymphony/webwork/views/jsp/ui/RadioTest.java;
/cvs/webwork/src/test/com/opensymphony/webwork/views/jsp/ui/RadioTest.java,v <-- RadioTest.java
new revision: 1.19; previous revision: 1.18

Thanks Vlad.