struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jukka Välimaa" <valimaa.ju...@gmail.com>
Subject S2 type conversion problem with generics
Date Wed, 20 Aug 2008 15:17:51 GMT
Hi all,

I have the following problem which I think is caused by Struts 2 type
conversion.

I have a class I use to wrap a map for easier interface with view:

public class ObjectWeekHandler<T> {
    private Map<WeekDayEntry, T> weekDayObjects = new HashMap<WeekDayEntry,
T>();

    public Map<WeekDayEntry, T> getWeekDayObjects() {
        return weekDayObjects;
    }

    public void setWeekDayObjects(Map<WeekDayEntry, T> weekDayObjects) {
        this.weekDayObjects = weekDayObjects;
    }

    public T getEvenMonObject() {
        return weekDayObjects.get(WeekDayEntry.EVEN_MONDAY);
    }

    public void setEvenMonObject(T evenMonObject) {
        weekDayObjects.put(WeekDayEntry.EVEN_MONDAY, evenMonObject);
    }

    [...]

I use this class in my action class to get strings for various weekdays:
private ObjectWeekHandler<String> weekDayTruckIds = new
ObjectWeekHandler<String>();

public ObjectWeekHandler<String> getWeekDayIds() {
        return weekDayIds;
 }

When I send the request, the parameters are of this type:
    weekDayIds.evenMonObject=-1

If I understand the workings of Struts 2 type conversion correctly, it
should call getWeekDayIds.setEvenMonObject(type converted parameter value).
This is indeed what happens, but instead of setting the parameter as String,
it is set as String array. The same thing happens if I parameterize
weekDayIds as weekDayIds<Long>.

I have an ugly workaround in place- I cast the supposed String value I get
from getEvenMonObject into Object and then into String[], and get the first
value. It works, but I certainly don't like it. Does anyone have an idea
what might be wrong and how to fix it?

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message