On Thu, 19 May 2011 20:14:09 -0300, Vangel V. Ajanovski <[email protected]>
wrote:
Hi Thiago,
Hi!
It was just a few days ago that I discovered the SelectModelFactory
service.
Nice! Use it! :)
In the past I have used the selectObject component described here:
http://wiki.apache.org/tapestry/Tapestry5SelectObject
Not everything in the wiki I'd consider good. See this thread:
http://tapestry.1045711.n5.nabble.com/Enum-or-Drop-Down-td3394312.html#a3394448
The only problem with this is that the Generic encoder puts the label as
the id of the option, so retrieval is but value, not by id, which can be
sometimes problematic.
But, this page references few other approaches as *better*, and you have
made a comment that they are wrong approaches. I have noticed this
comment just two days ago. Do you think this approach is also not good?
I've posted a suggestions for that in the list once.
If you have some property that is unique, that's what I'd use instead of
just concatenating them all.
How could we achieve the same as I described but with the help of the
SelectModelFactory
SelectModelFactory deals with SelectModels, not with ValueEncoders. What
many people seem to not understand is that SelectModel and ValueEncoder
represent and implement different things.
SelectModel is a collection of options. Basically, each option is a value
(an object) and a label (presented to the user).
ValueEncoder makes the mapping between each object used as option and a
string that uniquely identifies it and vice-versa. In other words, it
deals with the value attribute of <option>. toClient() should return the
id of the received object. toValue() should return the object that has a
given id. This last method is usually implemented using a database lookup
(using a DAO or otherwise). Just do what the Javadoc tells you to do.
If you're using tapestry-hibernate, the ValueEncoder is automatically
added for every of your mapped entity classes. It's implementation is
simple: it uses the primary key field of the object and converts it to a
String and vice-versa. That's what you should do in your hand-coded
ValueEncoders too.
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]