Re: Redirect to a component action
Re: Redirect to a component action
- Subject: Re: Redirect to a component action
- From: Hugi Thordarson <email@hidden>
- Date: Sat, 22 Aug 2009 13:31:39 +0000
Well, you have passed the login page an instance of your component, so
you can invoke any method you like on it. If you'd like to do this in
a flexible way, you could for example pass a selector to the login
component, and use it to invoke a method on a successful login. Here's
a little example of this might work, see the attached components.
Attachment:
CartComponent.java
Description: Binary data
Attachment:
Login.java
Description: Binary data
Save my cart
Perform login
Note that the action you call can of course be the saveCart() action,
and then return its WOActionResults. (In this case, you'd just skipt
the whole "pageToReturn"-thingamabob, and on login, just return the
selector's invocation results). Just make sure saveCart() is then
returning an instance of a new/different component and not "null" or
"context().page()". Otherwise you'll just be returning the login
component again :).
Cheers,
- hugi
On 22.8.2009, at 13:12, Francesco Romano wrote:
On 22/ago/2009, at 14.32, Hugi Thordarson <email@hidden> wrote:
Hi Francesco.
One option you have is to store a reference to the original page in
the Login page. Something like this (warning: uncompiled pseudocode):
/*----------------------------------------------*/
// in your shopping cart component:
/*----------------------------------------------*/
public WOActionResults saveCart() {
if( session().user() == null ) {
LoginPage nextPage = pageWithName( nextPage.class );
nextPage.componentToReturnToAfterLogin = context().page();
return nextPage;
}
else {
// Do your thing;
}
}
/*----------------------------------------------*/
In your login page
/*----------------------------------------------*/
public WOComponent componentToReturnToAfterLogin;
public WOActionResults login() {
// authenticate the user. Then, on successful login...
componentToReturnToAfterLogin.ensureAwakeInContext( context() );
return componentToReturnToAfterLogin;
}
/*----------------------------------------------*/
This way, your user will be returned to the original page after
logging in. Note, however, that this will of course not invoke your
saveCart() action when you return, you'll have to do that in a
different way.
So it's impossible to call an action from another component?
Maybe I can set a flag in the cart component and manually call the
action..
What do you think?
Francesco
Cheers,
- Hugi
// Hugi Thordarson
// http://hugi.karlmenn.is/
On 22.8.2009, at 08:40, Francesco Romano wrote:
Hi..
I have a component action that does a check if the user is logged
in..
If the user is not logged in, I redirect to a login page.
Now... I would like that, after the successful login, the first
component action is called...
So.. something like this:
public WOActionResult saveCart() {
if (session().user == null)
->redirect to LoginPage
else
doSomething
The login action is a direct action..
How can I redirect from the login action to the saveCart action??
Thanks.
Francesco
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden