right, so I'm assuming you're iterating over a list of all books somehow. This is how I did something similar. In your submitting jsp:
<c:forEach items="${books}" var="row">
.....
<html:multibox property="bookList">
<c:out value="${row.bookKey}"/>
</html:multibox>
......
</c:forEach>


in your struts-config:
       <form-bean
           name="booktForm"
           type="org.apache.struts.validator.DynaValidatorActionForm">
           <form-property name="bookList" type="java.lang.String[]"/>
            ...

in your action:
       if( form instanceof DynaActionForm ){
           DynaActionForm dynaForm = ((DynaActionForm)form);
           String[] bookList = dynaForm.get("bookList");
        ......


From: "Samyukta Akunuru" <[EMAIL PROTECTED]>
Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Subject: RE: Struts check box validation question
Date: Tue, 10 Feb 2004 14:46:46 -0600

Ben,

I am using a checkbox.
What I am planning to do is allow the user to check/select items/checkboxes on the book display page and check/select the books he wants to delete from Book store.
On submitting the form, I want to capture the set/list of checked choices so that I can take it as a array and pass it to my deleteBooks() method in my Action class.
Please let me know if I was not clear and I could append my sample code snippets.
I appreciate your swift replies


Thanks,
~Samy

-----Original Message-----
From: Ben Anderson [mailto:[EMAIL PROTECTED]
Sent: Tuesday, February 10, 2004 2:37 PM
To: [EMAIL PROTECTED]
Subject: RE: Struts check box validation question


not too sure what you mean by your question, but I'd say no, you don't need to pass in the array. You're using a String[] as the form property, right? Are you using multibox?

http://jakarta.apache.org/struts/userGuide/struts-html.html#multibox

>From: "Samyukta Akunuru" <[EMAIL PROTECTED]>
>Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>Subject: RE: Struts check box validation question
>Date: Tue, 10 Feb 2004 14:30:34 -0600
>
>Thanks Ben, I am looking at the code closer now, but do we have to pass in
>the array of selections to the ActionForm class from the jsp....
>
>Regards,
>Samy.
>
>-----Original Message-----
>From: Ben Anderson [mailto:[EMAIL PROTECTED]
>Sent: Tuesday, February 10, 2004 2:28 PM
>To: [EMAIL PROTECTED]
>Subject: RE: Struts check box validation question
>
>
>Here's code I got from Kris Schneider. It validates that at least one of
>the check boxes was checked, but you should be able to change it fairly
>easily to do whatever you want. If you're wondering how this code fits in,
>check out:
>http://jakarta.apache.org/struts/userGuide/dev_validator.html
>and look at validateTwoFields to see how to setup of custom validate
>methods.
>
> public static boolean validateRequiredArray(Object bean,
> ValidatorAction va,
> Field field,
> ActionErrors errors,
> HttpServletRequest
>request)
>{
> boolean isValid = false;
>
> LOG.debug("bean: " + bean);
>
> Object[] array = null;
> if (isArray(bean)) {
> array = (Object[])bean;
> } else {
> Object fieldProperty = null;
> try {
> fieldProperty = PropertyUtils.getProperty(bean,
>field.getProperty());
> } catch (Exception exc) {
> // TODO: throw runtime exception?
> LOG.error(exc.getMessage(), exc);
> }
> LOG.debug("fieldProperty: " + fieldProperty);
> if (isArray(fieldProperty)) {
> array = (Object[])fieldProperty;
> }
> }
>
> if (array != null) {
> for (int i = 0, n = array.length; i < n; i++) {
> Object obj = array[i];
> LOG.debug("array[" + i + "]: '" + obj + "'");
> String value = ((obj == null) ? null : obj.toString());
> if (!GenericValidator.isBlankOrNull(value)) {
> isValid = true;
> break;
> }
> }
> }
>
> if (!isValid) {
> errors.add(field.getKey(), Resources.getActionError(request,
>va,
>field));
> }
>
> LOG.debug("isValid: " + isValid);
>
> return isValid;
> }
>
> public static boolean isArray(Object obj) {
> return ((obj == null) || obj.getClass().isArray());
> }
>}
>
>-Ben
>
> >From: "Samyukta Akunuru" <[EMAIL PROTECTED]>
> >Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> >To: <[EMAIL PROTECTED]>
> >Subject: Struts check box validation question
> >Date: Tue, 10 Feb 2004 12:57:23 -0600
> >
> >Had a quick question on power of struts form validation.Sample code to
> >validate checkboxes checked on the jsp, which will be sent as an array to
> >the Struts Action Form. Tips appreciate.Thanks in advance!
> >
> >Best Regards,
> >Samy
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> >
>
>_________________________________________________________________
>Plan your next US getaway to one of the super destinations here.
>http://special.msn.com/local/hotdestinations.armx
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>


_________________________________________________________________
Check out the great features of the new MSN 9 Dial-up, with the MSN Dial-up
Accelerator. http://click.atdmt.com/AVE/go/onm00200361ave/direct/01/


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]


_________________________________________________________________
Create your own personal Web page with the info you use most, at My MSN. http://click.atdmt.com/AVE/go/onm00200364ave/direct/01/



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to