struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Devine <johnjdev...@comcast.net>
Subject RE: Accepting arrays as values in mapped-backed ActionForms
Date Tue, 04 Mar 2003 18:51:57 GMT
Hello Struts community!

No one's picked up on this thread and I just wonder whether it's a
stupid or unclear question or whether it's just not of interest. 

If the question's been answered before, could someone let me know and
I'll go back to searching lists. I didn't find any answers earlier.

Basically what I'm trying to is set up a form that will contain a Map of
String arrays. At this point, when Struts populates the Map, it assumes
the map elements will be plain strings. Does anyone know of a way to
tell it that the members of the map should be populated as arrays
(because multiple request parameters will have the same name).

Thanks in advance for any response,

John Devine




-----Original Message-----
From: John Devine [mailto:johnjdevine@comcast.net] 
Sent: Monday, March 03, 2003 5:10 PM
To: struts-user@jakarta.apache.org
Subject: Accepting arrays as values in mapped-backed ActionForms

Does anyone know how to specify that the value of the HashMap in a
mapped-backed ActionForm should be an array of Strings rather than just
a single String?

I'm having a problem in trying to set up a page of several rows of
indexed multi-boxes:

I have a regular action form that includes:

   public Map existingGroups = new HashMap();

   public Map getExistingGroups(){
      return existingGroups;
   }

   public void setExistingGroups(Map map){
      this.existingGroups = map;
   }

On my JSP, I include several different rows of multiboxes, and I want
the user to be able to choose different groups for each object:

<%
List storyList = searchBean.getList();
int counter = 1; 
for (Iterator i = storyList.iterator(); i.hasNext(); counter++ ) { 
   Story story = (Story)i.next(); 
   pageContext.setAttribute("story", story); 
   pageContext.setAttribute("counter", new Integer(counter)); 
%>

<tr>
  <td>
   <bean:write name="story" property="title" />
  </td>
<logic:iterate id="group" name="submitToGroupForm"
property="availableGroups" type="com.rd.Group" >
  <td>
   <html:multibox property='<%="existingGroups("+story.getId()+")"%>'  >
    <bean:write name="group" property="id" />
   </html:multibox>
    <bean:write name="group" property="name" />
  </td>
</logic:iterate>
</tr>

<% } %>

(Oh, and I use the scriptlet iteration because there's a tile being
called within that loop that I edited out for readability.)

What happens is that value of "existingGroups(primaryKey1)" is a String
instead of an array of Strings. So that if I try to cast it to String[],
I get a ClassCastException.

Is this a limitation of using maps in forms, or is there a way to return
arrays of strings as entries of the Map on your ActionForm?

Thanks,

John


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message