• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

multibox issue with DynaValidatorForm

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try changing your "charistics" variable from a String to a String array. Example:
 
reply
    Bookmark Topic Watch Topic
  • New Topic