Hi Spencer,
Cycle.activate has no effect in the page render listeners - it only
works in action listeners. That is why you have to throw the
PageRedirectException. Annoying but true.
A simpler way to do this would be to do your login checking in
pageValidate (PageValidateListener), have a persistent nextPage property
on your LoginPage class, and set it something like this...
class SomePage ... implements PageValidateListener{
@InjectPage("LoginPage")
public abstract LoginPage getLoginPage();
public void pageValidate(...){
if(!loggedIn()){
LoginPage page = getLoginPage();
page.setNextPage(cycle.getPage().getPageName());
throw new PageRedirectException(page);
}
}
}
class LoginPage ...{
public abstract void setNextPage(String name);
@Persist("client")
public abstract String getNextPage();
public void doLogin(IRequestCycle cycle){
if(loginOK()){
cycle.activate(getPageName());
}
}
}
That should work.
Best wishes
John
-----Original Message-----
From: Spencer Crissman [mailto:[EMAIL PROTECTED]
Sent: Wednesday, December 14, 2005 2:28 PM
To: Tapestry users
Subject: Re: Cycle not activating pages/callbacks
Thanks for your responses so far!
The thing is, at this point, there is no login form. In the login
page's
page begin render, I just manually perform the callback, so I should be
getting the same page instance that the original page redirects to. In
the
final app, there will obviously be a form, and I would need to persist
the
callback between submits, but since I immediately perform the callback
after
the redirect, there shouldn't be a need to.
In any case, for arguments sake, I went ahead and persisted the
Callback,
but I'm still getting the same results. Altering the code to validate
that
the callback is actually set shows that the callback is properly
configured
to redirect me to the original page (Home in this case), but the
performCallback never actually renders.
code:
if ( getCallback() != null )
{
System.out.println("About to perform callback...");
System.out.println(" Callback: " +
getCallback().toString()
);
getCallback().performCallback(cycle);
}
result:
About to perform callback...
Callback: PageCallback[Home]
After which the login page finishes rendering, with no sign of the Home
page..
So, any other ideas regarding this? I still don't see why the original
page's cycle.activate had to be replaced with a PageRedirectException,
as I
thought that is the whole point of the cycle.activate function. It is
less
critical that I get an answer with that, because I can use a workaround,
but
I would like to understand why the workaround is required.
The performCallback() seems to be doing absolutely nothing, and since
both
it and the original call work on the cycle, I can't help but think they
are
related, but determining the why with the performCallback is much more
important, as I haven't a workaround for that.
Thanks again for any thoughts!
Spencer
-----
On 12/13/05, Ron Piterman <[EMAIL PROTECTED]> wrote:
>
> too quick a replay - sorry -
> you have to persist the callback in a way of your choice, because it
> probably dissapears after the login page renders...
>
>
> Spencer Crissman wrote:
> > I have an T4 (b11) app where I am implementing some redirection for
the
> > authentication portion of my pages. When the user attempts to
access
> the
> > first page, it redirects them to login if they aren't logged in, and
> then
> > after they've logged in, it redirects them to the original page.
Pretty
> > standard fare.
> >
> > Well, I have some code along the following lines:
> >
> > Login loginPage = cycle.getPage( "Login" );
> > loginPage.setCallback( new PageCallback(getPageName() ) );
> > cycle.activate(loginPage);
> > return;
> >
> > When the above runs, the login page never gets activated. The
original
> page
> > just finishes rendering, and that's it.
> > Changing:
> > cycle.activate(loginPage);
> > To:
> > throw new PageRedirectException(login);
> >
> > Caused the login page to come up successfully, however in the login
> page,
> > the following code:
> >
> > // Authentication checks out...
> > getCallback().performCallback(cycle);
> >
> > Also does nothing. The login page renders, and that is it.
> >
> > It seems like my cycle(s) are not redirecting to the pages they are
> supposed
> > to. Can anyone offer some insight as to why that would happen, and
what
> I
> > could do about it?
> >
> >
> > Thanks in advance!
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]