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 H <ga...@hotmail.com> on 2003/06/02 23:53:58 UTC

Map-backed action form and multibox problem

Hi,

I’m working on an application that’s designed to render dynamic pages that 
take as input an ArrayList of DisplayItemBeans.  Each DisplayItemBean has 
properties that define:
(a) the UI widget type (text, checkbox, radio button, etc)
(b) the data item’s db column name (used as key in an action form Map)
(c) for selection-type widgets (listbox, checkbox, radio button), a list of 
available options.

I defined a Map-backed ActionForm and a jsp template to work with this 
ArrayList (pls see code snippets below).  The pages render fine for all 
types of widgets except checkboxes.  When I use the html:multibox tag, I 
encounter the following problem:

[ServletException in:/WEB-INF/jsp/dynaBody.jsp] No getter method available 
for property multibox_key_name for bean under name 
org.apache.struts.taglib.html.BEAN'

However, using the same code, if I just change the widget type to radio 
button or select, things work fine.  I’d appreciate any comments on what I 
did wrong and suggestions on how I can fix it.

Thanks

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

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

public class OnlsDynaActionForm extends ActionForm {

   public OnlsDynaActionForm() {
	super();
   }

   //QUES: Sample from jakarta website declared this Map as final.
   //Does it need to be final? What's the advantage of using final?
   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="<%=dib.getDb_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>

_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8. 
http://join.msn.com/?page=features/junkmail


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


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

Posted by C <ga...@hotmail.com>.
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