struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex <>
Subject Inserting data into nested collections
Date Mon, 01 Mar 2010 17:56:08 GMT
Hi list,

I am having hard time figuring out how to solve what seems to be a somewhat
trivial problem ...

I am using Struts 2 and OGNL in my JSP to send textfield values in my Action

The struts Action looks something like this :

public class MyAction extends ActionSupport {

       HashMap<String, ArrayList<String>> customAltTerms = new
HashMap<String, ArrayList<String>>();

        * @return the customAltTerms
       public HashMap<String, ArrayList<String>> getCustomAltTerms() {
               return customAltTerms;

        * @param customAltTerms the customAltTerms to set
       public void setCustomAltTerms(HashMap<
String, ArrayList<String>> customAltTerms) {
               this.customAltTerms = customAltTerms;

public String execute() throws Exception{

.... some code here to test what's in the hashmap after the form has been


 .... other methods of the Action class


I am unable to insert the data collected from the textfields of the form
into the HashMap.

I have tried the following in my JSP :

<s:textfield name="customAltTerms['someKey1'].value" />


<s:textfield name="customAltTerms['someKey1'].value[0]" />


<s:textfield name="customAltTerms['someKey1'][0]" />


<s:textfield name="customAltTerms['someKey1'].[0]" />

I almost always end up with java.lang.String cannot be cast to
java.lang.ClassCastException: java.lang.String cannot be cast to
etc ...

I also tried replacing the ArrayList with a String[] with the same result

However if I use a HashMap<String, String> the key and the value are
populated correctly.But of course I only get one value per key which is not
what I intend to do.

What syntax must I use in the "name" attribute of the textfield to have the
actual value of the textefield inserted in the ArrayList containend in the
HashMap for the given key?

Thank you for helping me.

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