Re: [T5.1] @SessionState an generic pages

2009-06-24 Thread Piero Sartini
 protected ClassT getValueClass()
 {
   return (ClassT) ((ParameterizedType)
 getClass().getGenericSuperclass()).getActualTypeArguments()[0]; }

 I use something similar in DAOs, idea came from here:
 https://www.hibernate.org/328.html

Thanks!! Had an abstract getEntityClass() method for my repositories as well. 
Never liked it.. and now I am able to get rid of them :-)

Piero

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



Re: Re: [T5.1] @SessionState an generic pages

2009-06-23 Thread nille hammer
Hi Thiago,

 Hi Hammer! :)
Friends call me nille.

 Hey! That's my open source code being used by someone besides me! Nice. :D
Just trying to learn from the masters ;-)

 .Maybe the solution to what you want to do is to use  
 ApplicationStateManager directly.
That's the trick! Thinking about your hint I rewrote GenericEntityPageT a 
bit. Code follows:

public abstract class GenericEntityPageT extends AbstractPage {
@Inject
private ApplicationStateManager manager;

public T getValue() {
return this.manager.get(this.getValueClass());
}

protected void setValue(final T value ) {
this.manager.set(this.getValueClass(), value);
}

public boolean isValueExists() {
return this.manager.exists(this.getValueClass());
}

@OnEvent(value = EventConstants.ACTIVATE)
Object checkValueExists() {
if (!this.isValueExists()) {
return this.getForwardPage();
}
else {
return null;
}
}

/**
 * @return the page to be forwarded to in case value does not exist as 
SSO
 */
protected abstract Object getForwardPage();

/**
 * @return the value's class in the implementing page
 */
protected abstract ClassT getValueClass();
}

Now it works like a charm.   Muitíssimo obrigado for putting me on the right 
track.
nillehammer

==
http://www.winfonet.eu

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



Re: Re: [T5.1] @SessionState an generic pages

2009-06-23 Thread Martin Strand
On Tue, 23 Jun 2009 22:32:25 +0200, nille hammer 
tapestry.nilleham...@winfonet.eu wrote:

 That's the trick! Thinking about your hint I rewrote GenericEntityPageT a 
 bit. Code follows:

   /**
* @return the page to be forwarded to in case value does not exist as 
 SSO
*/
   protected abstract Object getForwardPage();

   /**
* @return the value's class in the implementing page
*/
   protected abstract ClassT getValueClass();



Actually, getValueClass() doesn't have to be abstract. It can look like this:


protected ClassT getValueClass()
{
return (ClassT) ((ParameterizedType) 
getClass().getGenericSuperclass()).getActualTypeArguments()[0];
}


I use something similar in DAOs, idea came from here:
https://www.hibernate.org/328.html

Martin

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



Re: Re: Re: [T5.1] @SessionState an generic pages

2009-06-23 Thread nille hammer
Hi Martin,
thanks for the hint.
 
 protected ClassT getValueClass()
 {
   return (ClassT) ((ParameterizedType)
 getClass().getGenericSuperclass()).getActualTypeArguments()[0];
 }
 
 
 I use something similar in DAOs, idea came from here:
 https://www.hibernate.org/328.html

Similar to the example you provided, I have erased the method and use a field 
now. This way the value's class needn't be calculated several times but only 
once at page instanciation.
/**
 * the value's class in the implementing page
 */
@SuppressWarnings(unchecked)
private final ClassT classOfValue = (ClassT) ((ParameterizedType) 
this

.getClass().getGenericSuperclass()).getActualTypeArguments()[0];

Regards, nillehammer

==
http://www.winfonet.eu

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



Re: Re: [T5.1] @SessionState an generic pages

2009-06-23 Thread Thiago H. de Paula Figueiredo
Em Tue, 23 Jun 2009 17:32:25 -0300, nille hammer  
tapestry.nilleham...@winfonet.eu escreveu:



Hi Thiago,


Hi Nille!


Hi Hammer! :)

Friends call me nille.


Just joking. :P

Hey! That's my open source code being used by someone besides me! Nice.  
:D

Just trying to learn from the masters ;-)


I'm not a master, just someone who love to help people in the list. :)


.Maybe the solution to what you want to do is to use
ApplicationStateManager directly.
That's the trick! Thinking about your hint I rewrote   
GenericEntityPageT a bit.


Nice! I'm just a little puzzle why you don't use @Persist instead of using  
session state objects . ..


--
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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



Re: [T5.1] @SessionState an generic pages

2009-06-22 Thread Thiago H. de Paula Figueiredo
Em Mon, 22 Jun 2009 19:08:40 -0300, nille hammer  
tapestry.nilleham...@winfonet.eu escreveu:



Hi List,


Hi Hammer! :)


@SessionState
private T value;


@SessionState is handled by ApplicationStateManager per type, so I guess  
that it looked at your field and saw an Object.


I have looked for inspiration on ars-machina  
(http://www.arsmachina.com.br/project/tapestrycrud/usage).


Hey! That's my open source code being used by someone besides me! Nice. :D

But there the generic values aren't used as SessionState but get/set in  
the code. Is it somehow possible to use generic fields as SessionState  
values?


Tapestry CRUD (one of the packages in the Ars Machina Project) has a  
class, BaseEditPage, that should be the one you were looking. But it uses  
@Persist, not @SessionState, and they're handled a little bit differently  
by Tapestry. Maybe the solution to what you want to do is to use  
ApplicationStateManager directly, but I guess you should use @Persist  
instead of @SessionState.


--
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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