You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Angelo Chen <an...@yahoo.com.hk> on 2008/09/03 15:41:19 UTC

t5: using a non primary key field as context

Hi,

I like the feature that we can now pass Hibernate entity to the onActivate
and T5 automatically picks up object from database. however it assumes what
passed is the primary key, example:

1. this works.
localhost://page/1

2. this will not work:
localhost://page/myName

is there a way to tell T5 that to use a particular field to pick up the
object?

thanks,

sample code follows:

public class Page 
{ 
  private Person person; 

  void onActivate(Person person) 
  { 
    this.person = person; 
  } 

  Object onPassivate() 
  { 
      return this.person; 
  } 
}


-- 
View this message in context: http://www.nabble.com/t5%3A-using-a-non-primary-key-field-as-context-tp19289427p19289427.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: t5: using a non primary key field as context

Posted by Chris Lewis <ch...@bellsouth.net>.
Hi,

I've wondered the same thing and taken a quick look at it. I'm pretty
sure that it can be done, but the big issue is how to identify what the
activation context's value means to the entity? With a PK it's easy to
make assumptions (cast the context value and if it can be cast to a long
and the context argument type is a known hibernate entity, load it from
the ORM). Anyway, take a look at the tapestry-hibernate source and pay
close attention to the PK-based ValueEncoders - because you'll need to
create a new one - and also to how it registers them with hibernate
entities.

good luck and please share any troubles/victories

chris

Angelo Chen wrote:
> Hi,
>
> I like the feature that we can now pass Hibernate entity to the onActivate
> and T5 automatically picks up object from database. however it assumes what
> passed is the primary key, example:
>
> 1. this works.
> localhost://page/1
>
> 2. this will not work:
> localhost://page/myName
>
> is there a way to tell T5 that to use a particular field to pick up the
> object?
>
> thanks,
>
> sample code follows:
>
> public class Page 
> { 
>   private Person person; 
>
>   void onActivate(Person person) 
>   { 
>     this.person = person; 
>   } 
>
>   Object onPassivate() 
>   { 
>       return this.person; 
>   } 
> }
>
>
>   

-- 
http://thegodcode.net


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: t5: using a non primary key field as context

Posted by Ulrich Stärk <ul...@spielviel.de>.
Try the following. It's not automatic but should provide the desired behaviour.

private EntityType entity;

@Inject
private Session session;

void onActivate(String searchString)
{
   this.entity = (EntityType) Session.createQuery("from EntityType e where 
e.field=:searchString").setParameter("searchString", searchString).uniqueResult();
}

Cheers,

Uli


Angelo Chen schrieb:
> Hi,
> 
> I like the feature that we can now pass Hibernate entity to the onActivate
> and T5 automatically picks up object from database. however it assumes what
> passed is the primary key, example:
> 
> 1. this works.
> localhost://page/1
> 
> 2. this will not work:
> localhost://page/myName
> 
> is there a way to tell T5 that to use a particular field to pick up the
> object?
> 
> thanks,
> 
> sample code follows:
> 
> public class Page 
> { 
>   private Person person; 
> 
>   void onActivate(Person person) 
>   { 
>     this.person = person; 
>   } 
> 
>   Object onPassivate() 
>   { 
>       return this.person; 
>   } 
> }
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org