Do you need one checkbox or a series of checkboxes?

For one checkbox you write something like this (from the article):
<html:checkbox property="married" value="yes"/>

For a group of checkbox you can create several checkbox HTML elements
with the same name (this is what <html:multibox> does for you).

Looking at the example from the article, "customers" is an ArrayList
of Customer object, they are queued to request object at every HTTP
request, but they can be stored in the session as well and nothing
will change. This is just a list of customers, their properties do not
change. The example uses customer IDs to select/deselect checkboxes
that correspond to customers.

When the following is processed,

 <html:multibox property="control">
   <bean:write name="customer" property="id"/>
 </html:multibox>

the <input type="checkbox" name="control" ...> are generated. They
have "value" attribute provided by <bean:write> tag. How come? Because
in this particular case <bean:write> is the body of <html:multibox>
tag. See description of <html:multibox> tag for explanation:
http://struts.apache.org/1.x/struts-taglib/tlddoc/html/multibox.html .

Then you check some boxes, and browser submits something like this:
http://mysite/myboxes.do?control=001&control=003

Struts initializes multiSelectForm ActionForm, creates "control" array
as its property, and fills its elements with the values above. Next
time the JSP is displayed, these values are matched against IDs of
Customer objects, and appropriate checkboxes are marked as checked.

I agree it is kinda convoluted ;-)

The article has downloadable samples and the source code, study it, it
is quite helpful.

Michael.

On 8/28/06, Anthony N. Frasso <[EMAIL PROTECTED]> wrote:
Thanks, I appreciate the quick response.
Unfortunately, I'm not sure that this addresses my
issue, unless I've misunderstood something.  It
doesn't really mention how to populate a checkbox with
a value... but it does provide the following:

<logic:iterate id="customer" name="customers">
  <html:multibox property="control">
    <bean:write name="customer" property="id"/>
  </html:multibox>
  <bean:write name="customer" property="fullName"/>
  <br>
</logic:iterate>

This creates a checkbox for each customer in a
collection of customers.  It supposedly creates the
following html:

<input type="checkbox" name="control" value="001"
checked="checked">
John Doe
<br>
<input type="checkbox" name="control" value="002">
Peter Smith
<br>

What I don't understand is how it determines that John
Doe should have his checkbox checked, but not Peter
Smith.

Do you have any ideas?

Thanks,
Anthony Frasso

--- Michael Jouravlev <[EMAIL PROTECTED]> wrote:

> On 8/28/06, Anthony N. Frasso <[EMAIL PROTECTED]>
> wrote:
> > Hello all, and thanks for your help in advance.
> >
> > I have a relatively simple JSP that I'm trying to
> > present.  I have a bean that is accessible as an
> > attribute in the request, as well as a form bean
> for
> > the form on this page.  As an example, here is one
> of
> > the input components for the form:
> >
> > <html:text property="name" value="${bean.name}" />
> >
> > This takes the value of the "name" property in the
> > bean and initializes the text box with this value.
> > When the form is submitted, it takes the value
> from
> > the text box and places it into the "name"
> property of
> > the form bean.
> >
> > I'd like to do something similar with a checkbox.
> > However, I don't see any way to initialize the
> > checkbox.  The value property works in a different
> way
> > than in most of the other form input tags.  How
> would
> > I go about accomplishing this?
> >
> > Thanks again,
> > Anthony Frasso
>
> The first entry that comes up in Google when
> searching for "struts
> <html:checkbox>":
>
http://javaboutique.internet.com/tutorials/strutsform/
>
>


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

---------------------------------------------------------------------
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]

Reply via email to