Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multibox issue with DynaValidatorForm

 
Scott Updike
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a context-scoped LabelValueBean called "selectcharistics" that drives the display of a multibox element on a jsp page. The jsp page snippet is below:

<c:foreach var="chars" items="${selectcharistics}">
<html:multibox property="charistics">${chars.value}</html:multibox>${chars.label}
</c:foreach>


Whenever the form is submitted I get and handle the array of strings (containing the ${chars.value}) that are selected. However, I don't know how to properly handle the multibox element in my DynaValidatorForm so that if the form fails the validation, the resulting error screen populates the checkboxes previously selected.

My struts-config.xml looks something like this:

<form-bean name="insert" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name = "name" type="java.lang.String"/>
<form-property name = "charistics" type="java.lang.String"/>
</form-bean>


Since charistics is really an array of Strings, is the type correct? Seems to me it should be set to Array, but that errors out as well. How can I configure the <form-bean> element properly so that the multibox elements that were checked prior to the form being submitted are checked in the resulting error screen? Here is a snippet of my jsp error screen (it currently errors out when validation fails):

<c:foreach var="chars" items="${selectcharistics}">
<html:multibox property="charistics"/>
</c:foreach>



If anyone can shed some light on this for me (or provide some good references with an example of this type of functionality), I would appreciate it!

Thanks,
Scott
 
Scott Updike
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This issue has been resolved. For those interested, I found my answer by continuing to dig through the Struts documentation on the Apache website. Basically, all you have to do is in the <form-bean> tags, since the multibox element is passing an array of Strings to the DynaValidatorForm routines, then the type attribute in the <form-bean> tag should be set to:

type="java.lang.String[]"

instead of

type="java.lang.String"
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try changing your "charistics" variable from a String to a String array. Example:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic