You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by George Ludwig <ge...@gmail.com> on 2011/10/01 09:43:14 UTC

Overriding onActivate() in page sublass appears to prevent access to session attributes/properties in subclass...?

I'm working on a Twitter authentication use case, i.e. log on to the
app via Twitter's oauth. It works well, except....

I have a Page superclass called MyPage that includes a getter/setter
method for a session attribute isAuthenticated. In order to protect
access to the pages, I check getIsAuthenticated() in the onActivate()
method of each page. If it's not true, I return the Index page, from
which they can authorize via Twitter.

Everything works, except when I move the isAuthenticated() check to
the onActivate() method of the MyPage superclass. It seems intuitive
to want do this because it's the same check on every page, except for
the Index page, which I override to return a null (otherwise,
naturally there is an infinite loop of calling onActivate() on Index
page after Index page).

Unfortunately, with the isAuthenticated() check in the MyPage
superclass onActivate() method, for some reason calls to
isAuthenticated() fails.

I have no idea why this is happening. I can live with the code as-is,
but I would love to understand why it fails when I use a simple OO
construct!

Here's the setter/getter from the MyPage superclass:

@SessionAttribute(IS_AUTHENTICATED_SESSION_ATTRIBUTE)
private Boolean isAuthenticated;
	
public Boolean getIsAuthenticated() {
	return isAuthenticated;
}

public void setIsAuthenticated(Boolean isAuthenticated) {
	this.isAuthenticated = isAuthenticated;
}

Here's the onActivate method where the check occurs:

@InjectPage
private Index index;
public Object onActivate() throws Exception {
	// check if we are authenticated
	if(getIsAuthenticated()==null || !getIsAuthenticated())
		return index;
	return null;
}

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