When extending the StrutsTypeConverter, is there anyway to figure out if
the "toClass" is a List<Integer> or a List<String>?  I have found that when
converting data from a submitted webpage that has a value of a List in a
single variable, the standard struts conversion fails.  For example:
<s:hidden name="integerList" value="%{integerList}" /> display as <s:hidden
name="integerList" value="[1,2,3,4,5]" />.  When the form submits, this
value will not convert properly back into the List.  In addition, the
conversion fails if you have a list of checkboxes and the user only checks
one -  hence only a single variable being converted to a List.

I have solved this issue by creating a MyListConverter, but I have to
declare the converter on each action in a [-conversion.properties] file
which is now becoming a bit cumbersome since this is such a common
occurrence. I have also declared some on my model/entity beans, but
still.... I would love to have a more global "List" converter, such as:

[xwork-conversion.properties]
java.util.List=com.afs.web.converter.MyListConverter

Thus any List that is encountered, I could attempt "my conversion" and send
up the chain of command if the resulting List is not of List<Integer> or
List<String>.

[Psuedo_Code]
public class MyListConverter extends StrutsTypeConverter {
    public Object convertFromString(Map context, String[] values, Class
toClass) {
        // Is toClass List<Integer>, then try "my" conversion

        // Else is toClass List<String?, then try "my" conversion

        // Else return performFallbackConversion(context, o, toClass);
    }
}

Any ideas?  Or am I going about this incorrectly?

Thanks in advance.

Reply via email to