You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by nille hammer <ta...@winfonet.eu> on 2009/06/23 00:08:40 UTC

[T5.1] @SessionState an generic pages

Hi List,

in many of my pages I find myself doing similar things. I collect data with a form and store it in a SessionState field. Then i forward to a summary page. In onActivate of summary page check for existence of SessionState value whith boolean valueExists. If value exists I show the summary and let user confirm.

To save me some code I thought of using Generic base page for that. The code follows:
public abstract class GenericEntityPage<T> {

    @SessionState
    private T value;

    private boolean valueExists;

    public T getValue() {
        return this.value;
    }

    public void setValue(final T value ) {
        this.value = value;
    }

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

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

Doing so I get an error "Could not find a coercion from type java.lang.Object to type xyz" on the subclass page. I have looked for inspiration on ars-machina (http://www.arsmachina.com.br/project/tapestrycrud/usage). 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?

Kind regards, nillehammer

==
http://www.winfonet.eu

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

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Mon, 22 Jun 2009 19:08:40 -0300, nille hammer  
<ta...@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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org