Re: Redirect to a component action
Re: Redirect to a component action
- Subject: Re: Redirect to a component action
- From: Mike Schrag <email@hidden>
- Date: Sat, 22 Aug 2009 09:33:48 -0400
You can also save the request URL, pass that into your login
component, and send a WORedirect back to the origina URL when you
successfully login ... you have to be a little careful that the URL
the requested isn't actually to the login page (for instance, if they
hit /wa/login, you don't want to keep sending them back to the login
page).
ms
On Aug 22, 2009, at 9:31 AM, Hugi Thordarson wrote:
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.
<CartComponent.java><Login.java><CartComponent.html><Login.html>
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
_______________________________________________
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