struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Devine <johnjdev...@comcast.net>
Subject Accepting arrays as values in mapped-backed ActionForms
Date Mon, 03 Mar 2003 23:09:56 GMT
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


Mime
View raw message