To add to Thiago's golden words, you can have a simple ListValueEncoder for
using index/toString() like this

class ListValueEncoder<T>(){
   final private List<T> values;

   public ListValueEncoder(List<T> values){
      this.values = values;
   }

   public String toClient(T value){
      return values.indexOf(value);
   }

   public Value toValue(String index){
      return values.get(Integer.parseInt(index));
   }
}

(Yes, you have to ensure equals() and hash() are properly overridden)

regards
Taha



On Mon, Feb 21, 2011 at 10:43 PM, Thiago H. de Paula Figueiredo <
thiag...@gmail.com> wrote:

> On Mon, 21 Feb 2011 14:05:25 -0300, robnangle <robnan...@gmail.com> wrote:
>
>  I am not using tapestry-hibernate, is there any examples out there because
>> the few I have came across seem to be very complex?
>>
>
> There are some examples out there that I consider the wrong approach,
> specifically implementing both ValueEncoder and SelectModel in the same
> class.
>
> Suppose you have a class User and a DAO for it named UserDAO (not tested):
>
> class UserValueEncoder<User>() {
>        final private UserDAO dao;
>        public UserValueEncoder(UserDAO dao) {
>                this.dao = dao;
>        }
>        public String toClient(User user) {
>                return user.getLogin();
>        }
>
>        public User toValue(String clientValue) {
>                return dao.findByLogin(clientValue);
>        }
> }
>
> @Property
> private User user;
>
> <select t:type="Select" value="user" .../>
>
> You could use any logic for that. For example, you could use the user id
> instead of login and your application would behave exactly the same.
>
>
> --
> 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: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

Reply via email to