I wrote a generic selection component that I am using a lot.  It is
based on someone else's work with the BeanSelectionModel, in Tap 4.
It uses Bean Utils.

http://www.phy6.net/wiki/tiki-index.php?page=Tapestry+5+GenericSelectionModel

This may help you out some.

Another thing I did to make things a bit easier on me, was to make my
domain pojo's implement an interface called "Selectable"  which forces
them to have a method called getLabel()

Then I can always specify "label" to the GenericSelectionModel, and
the beanutils will call getLabel();.

This way I can also aggregate some things into my getLabel() method,
like concatenating first and last names, etc.

i.e.

String getLabel(){
return lastname + ", " + firstname;
}


On 6/15/07, Erik Vullings <[EMAIL PROTECTED]> wrote:
Hi all,

I'm studying the <t:select... > component, which I want to use for
populating a select list with products, e.g. the HTML should look like
<select ...>
  <option value="productId1">Product 1</option>
  etc...

I've used it succesfully with a string of names (look at the BlockDemo
example in the source code), as well as with an ENUM (look at the
PaletteDemo example in the source code), but I actually have a list of
products, List<Product>. Each Product in the list has an Id, which should go
in the value part of the option, and it's name should be displayed. The
simplest approach, it seems, is to use the <t:Loop > component, and create
the HTML manually. Or does someone have a good example of how to use the
<t:select> component with a List?

I've looked at the SelectModel and SelectEncoder parameters of the
<t:select> component, but both are interfaces. The first has a
SelectModelImpl, which depends on a List<OptionModel>, yet another
interface, which has an OptionModelImpl. The SelectEncoder, however, only
has an implementation for ENUMs. However, to translate my own List<Product>
to a List<OptionModel> does not seem straightforward. Or am I missing
something? Could I use type coercion, for example.

Any help is appreciated!
Erik


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

Reply via email to