For this soloution won't you need to add the <view
name="login">Login.action</view> to each and every action that can throw a
ResultException(LOGIN,"whatever") ?

Could a way be devised to create global views ? Or something similar to
allow for these views to not have to be written in each case?

..Cam...

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]] On Behalf Of
Rajesh Duggal
Sent: Wednesday, 19 February 2003 12:20 PM
To: [EMAIL PROTECTED]
Subject: [OS-webwork] Re: How do I redirect to error pages?



For redirecting to the login page when a user isn't logged in and attempts
to access a "logged in user" only url.. I did the following...

I originally made my CreateProfileAction implement CommandDriven and made
the link from the main page href="createprofile!default.action",
but then I wanted the user to be redirected to the login page if they
weren't logged in or their session expired so this is what I did...

I overrided the doDefault method like so..
public String doDefault() throws Exception {
        checkUserLoggedIn(); return INPUT;
}

and created a checkUserLoggedIn() method like so...

private void checkUserLoggedIn() throws ResultException {
        if (session == null || session.get("screenname") == null) {
        throw new ResultException(LOGIN,"You must logged before creating a
profile.");
        }
}

I also put the checkUserLoggedIn() call at the beginning of the
doExecute() method.

And I put a login redirect.action in my actions.xml file.

And it works perfectly... if the user bookmarked the
createprofile!default.action url and tries to get to it without logging in
it redirects them to the login page.

Is there a better way to do this..? and/or any docs that explain the
method I used or any other method?  Should I add this technique to the
wiki? Ta, Raj.





-------------------------------------------------------
This SF.net email is sponsored by: SlickEdit Inc. Develop an edge. The
most comprehensive and flexible code editor you can use. Code faster.
C/C++, C#, Java, HTML, XML, many more. FREE 30-Day Trial.
www.slickedit.com/sourceforge
_______________________________________________
Opensymphony-webwork mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork

Attachment: smime.p7s
Description: application/pkcs7-signature

Reply via email to