aspose file tools*
The moose likes Struts and the fly likes multibox issue with DynaValidatorForm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "multibox issue with DynaValidatorForm" Watch "multibox issue with DynaValidatorForm" New topic
Author

multibox issue with DynaValidatorForm

Scott Updike
Ranch Hand

Joined: Feb 16, 2006
Posts: 92
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

Joined: Feb 16, 2006
Posts: 92
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

Joined: Feb 15, 2005
Posts: 4864
Try changing your "charistics" variable from a String to a String array. Example:


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: multibox issue with DynaValidatorForm