You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Brian Topping <to...@digidemic.com> on 2002/11/09 07:34:05 UTC

: how do I preselect some of the items?

Hi all,

Quick question that the online docs aren't helping me answer:

I have a snippet:

    <bean:define id="foo" name="FooForm" property="foo"
type="java.util.Collection"/>
    <html:form action="/doFoo.do">
      <html:select size=5 property="foofield">
        <html:options collection="foo" labelProperty="labelAttr"
property="valueAttr"/>
      </html:select>
    </html:form>

I can fill the <html:select> with the contents of the foo collection just
fine, but I am having problems understanding how to preselect items from the
rendered list.  In other words, if there are some large number of items in
the Collection, I'd like to be able to preselect some subset of them.
Ideally, I'd like to do so with a second collection that is somehow passed to
<html:options>.

Is this possible?

thanks for your consideration!

Brian

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: : how do I preselect some of the items?

Posted by "David M. Karr" <dm...@earthlink.net>.
>>>>> "Brian" == Brian Topping <to...@digidemic.com> writes:

    Brian> Hi all,
    Brian> Quick question that the online docs aren't helping me answer:

    Brian> I have a snippet:

    Brian>     <bean:define id="foo" name="FooForm" property="foo"
    Brian> type="java.util.Collection"/>
    Brian>     <html:form action="/doFoo.do">
    Brian>       <html:select size=5 property="foofield">
    Brian>         <html:options collection="foo" labelProperty="labelAttr"
    Brian> property="valueAttr"/>
    Brian>       </html:select>
    Brian>     </html:form>

    Brian> I can fill the <html:select> with the contents of the foo collection just
    Brian> fine, but I am having problems understanding how to preselect items from the
    Brian> rendered list.  In other words, if there are some large number of items in
    Brian> the Collection, I'd like to be able to preselect some subset of them.
    Brian> Ideally, I'd like to do so with a second collection that is somehow passed to
    Brian> <html:options>.

Look at the "struts-exercise-taglib" for an example of this.  The key is the
"html:select" tag.  The "property" attibute has to refer to a Collection, not a
scalar.  You'll also need to set the "multiple" attribute to "true".  I believe
you're right that the description of "html:select" doesn't make this clear.

-- 
===================================================================
David M. Karr          ; Java/J2EE/XML/Unix/C++
dmkarr@earthlink.net   ; SCJP



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>