You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by C <ga...@hotmail.com> on 2003/06/03 18:38:46 UTC

Map-backed action form and multibox problem (only 1st checked item detected)

I'm using a Map-backed action form to render dynamic pages. 
I'm having a problem with checkboxes, using the html:multibox
tag. If I display 3 choices and check two, only the first one is 
detected and sent to the back-end.  After pressing Submit, it appears 
that the ActionForm setter stores the field as a String, rather than 
String[] so I only get the first value.  (Please see code snippets 
below).  

If anyone can help me figure out how to make the multibox work with a 
Map-backed form, I'd really appreciate it.  I'm hoping that I
won't need to hardcode String[] properties in my ActionForm to
handle checkboxes as I'd like to make page rendering dynamic.

Thanks


------------- CODE SNIPPETS FOLLOW ----------------

Note:  I posted a similar message previously but found out the reason 
behind my `No getter method available' error.  The code below 
corrected that problem.

============= ACTION FORM =========================

public class MyDynaActionForm extends ActionForm {

   public MyDynaActionForm() {
	super();
   }

   private final Map values = new HashMap();

   public void setValue(String key, Object value) {
      values.put(key, value);   
   }

   public Object getValue(String key) {
      return values.get(key);
   }
}

======================= JSP =========================

[Assume that dispList, an ArrayList of DisplayItemBeans, exists in 
some scope and:
- has get/set methods for scrn_clmn (label to display), db_clmn 
(column name used as key in ActionForm map), options (ArrayList of 
LabelValueBeans containing choices for selection widgets)
- has helper methods such as isUITypeCheckbox() to identify what type 
of widget it is] 

<logic:iterate id="dib" name="dispList" type="DisplayItemBean" >
		
<tr> 
<bean:define id="db_clmn" value='<%= "value(" + dib.getDb_clmn() 
+ ")" %>'/>
  <td><bean:write name="dib" property="scrn_clmn" /></td>
  <td>
      <% if (dib.isUITypeCheckbox() ) { %>
	<logic:iterate id="opt" name="dib" property="options" 
type="org.apache.struts.util.LabelValueBean" >
	    <html:multibox  property="<%=db_clmn%>" >
	    <bean:write name="opt" property="value" />
	    </html:multibox>
	    <bean:write name="opt" property="label" />
	</logic:iterate>				
      <% } else if (dib.isUITypeRadiobutton() ) { %>
		... display using html:radio		
      <% } else if ...{ %>
		...handle other cases
      <% } %>
  </td>
</tr>
</logic:iterate>



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