Here is a simplified overview of what you need to do. If you still would
like code, I can still supply you with it, but I think this will be easier
to understand.
ActionForm:
2 fields with associated getter and setters:
String[] CheckboxNames
String[] CheckboxValues
You must populate this form before you hit the JSP to display it (if you
want to preset the values). So, figure out all the possible values, and
then figure out what you want checked. So, for example...
checkboxNames[0] = "String1";
checkboxNames[1] = "String2";
checkboxNames[2] = "String3";
checkboxNames[3] = "String4";
and
checkboxValues[0] = "String2";
checkboxValues[1] = "String4";
Then say
MyForm form = new MyForm();
form.setCheckboxNames(checkboxNames);
form.setCheckboxValues(checkboxValues);
And put the form in the session.
When you get to your jsp, retreive the form from the session, and place it
into the page context:
pageContext.setAttribute("MyForm", myform , PageContext.PAGE_SCOPE);
Then, where you want the multiple checkboxes on your jsp, do the following:
<html:form name="MyForm" action="entry.do" type="com.mypackagemname.MyForm">
<TABLE border="1">
<logic:iterate name="MyForm" property="CheckboxNames" id="item1">
<TR>
<TD align="center">
<bean:write name="item1" />
</TD>
<TD align="center">
<html:multibox property="CheckboxValues">
<bean:write name="item1" />
</html:multibox>
</TD>
</TR>
</logic:iterate>
</TABLE>
<html:submit value="Save Changes"/>
<html:reset/>
</html:form>
THen when you press submit and go to your actionClass, you can compare
CheckboxNames to CHeckboxValues to see what was checked.
Did that explain it enough?
Hope it helps,
Becky
----Original Message Follows----
From: Prashanth_Thm <[EMAIL PROTECTED]>
To: Becky Moyer <[EMAIL PROTECTED]>
Subject: RE: Struts Bug? My Bug? Help!! Please!
Date: Fri, 20 Jul 2001 16:23:53 -0400
Hi,
can you send me the code?
Actually i want to get the checked strings in my Action class which
i am not
able to....your code would be helpful to me.
and let me try to help you also if possible.
Prashanth.
> -----Original Message-----
> From: Becky Moyer [SMTP:[EMAIL PROTECTED]]
> Sent: Friday, July 20, 2001 1:20 PM
> To: [EMAIL PROTECTED]
> Subject: Struts Bug? My Bug? Help!! Please!
>
> I've got a multibox/iterate combination form. My webapp works when
> there
> is something to submit. When I check at least one value checked in my
> multiboxes, I get the expected result. When there is nothing checked in
> my
> multiboxes, my form object is the same as it was before I changed the
> checkboxes. For example, I'll have 4 checkboxes displayed, representing
4
>
> strings, String1, String2, String3, String4. I will check String2, press
> submit, and I receive the correct form in my ActionClass. After updating
> the form object and returning to my multibox page, if I uncheck String2
> and
> submit, the form I receive contains String2 as being checked.
>
> My form contains 3 String arrays, one of which contains links, one
> contains
> the string names, and the other contains the string names which are
> checked.
>
> I have done as much testing as I can, gone through my code, and cannot
> find
> a bug. Is this a bug (or perhaps it is a "feature" ;-) ) of Struts?
>
> If this isn't enough info, I can send code. What is going on?
>
> Thanks so much!
> Becky
>
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at
http://explorer.msn.com/intl.asp
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp