webtier@glassfish.java.net

Re: [webtier] SelectOne inside Datatable

From: Ryan Lubke <Ryan.Lubke_at_Sun.COM>
Date: Wed, 22 Jul 2009 07:59:02 -0700

On 7/22/09 1:10 AM, webtier_at_javadesktop.org wrote:
> Hi,
>
> I have a datatable in a jsf page. At every row there is a HtmlSelectOne component, and I need to populate these components with data, based on the value of the current row. For example if i had a table which iterates on categories, i need to populate the selectone-s with some data based on category id.
>
> How can a do that? I don't want my Category object to hold List<SelectItem> instances, because these are JSF things.
>
If you're using JSF 2.0, you don't need to provide collections of
SelectItem instances - you can provide a collection of model objects.

<h:selectOneMenu id="menu" value="#{bean.selectedValues}">
<f:selectItems value="#{bean.possibleValues}"
                                 var="value"
                                 itemLabel="#{value.label}" />
</h:selectManyListbox>

In the above example, #{bean.selectedValues} returns a Collection of
model objects.
f:selectItems will, using the value variable, create the SelectItem
instances for you with
each selectItem having a custom label based on the return of #{value.label}.

See the docs [1] for further details on the new options available in
f:selectItem(s).

If you're using 1.2, then you'll need to find a third party component
that accomplishes what you
desire (I believe Seam has select components that expose similar
functionality).

[1]
https://javaserverfaces.dev.java.net/nonav/docs/2.0/pdldocs/facelets/index.html

> [Message sent by forum member 'gabox01' (gabox01)]
>
> http://forums.java.net/jive/thread.jspa?messageID=356915
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: webtier-help_at_glassfish.dev.java.net
>
>