Re: Re: [T5.1] @SessionState an generic pages
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
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
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
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