how to redirect from prepare() method in struts 2

2009-01-24 Thread sagsai

Hello friends,
I have very little experience in struts 2  I have this typical requirement
where I feel that I have to redirect form the prepare() method when the user
is not logged in (by checking whether some session entries present or not).
Actually I am trying to avoid repetitive session checking  redirecting at
the beginning of every action method, for example
public String listUsers() throes Exception
{
//if (session.get(userType) != null 
session.get(userType).equals(admin))
//then show the result
   //otherwise redirect to the login page
}

public String viewDetails() throes Exception
{
//again code for the same checking
}
so I thought that since the prepare() method is being called every time some
action is being mapped to a method in this class so why not put the code for
checking  redirecting inside of prepare
like,
public void prepare() throws Exception
{
//if the user is not logged in
//redirect to the login page
}

But the problem is that I cannot return any string (which I can specify as
result of type redirect-action in the struts.xml file)since this function
has return type void also I could not find any method to redirect forcibly.

So, my question is whether it is possible to redirect form any method which
has not been mapped as an action at all?
if it can be done then how to do it?

Any ideas regarding this problem would really help.
Thanks in advance
-- 
View this message in context: 
http://www.nabble.com/how-to-redirect-from-prepare%28%29-method-in-struts-2-tp21643785p21643785.html
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: how to redirect from prepare() method in struts 2

2009-01-24 Thread Dave Newton
It would be much cleaner to put that kind of logic into an interceptor 
rather than in a prepare() method. It would cut down significantly on 
code duplication.


Dave

sagsai wrote:

Hello friends,
I have very little experience in struts 2  I have this typical requirement
where I feel that I have to redirect form the prepare() method when the user
is not logged in (by checking whether some session entries present or not).
Actually I am trying to avoid repetitive session checking  redirecting at
the beginning of every action method, for example
public String listUsers() throes Exception
{
//if (session.get(userType) != null 
session.get(userType).equals(admin))
//then show the result
   //otherwise redirect to the login page
}

public String viewDetails() throes Exception
{
//again code for the same checking
}
so I thought that since the prepare() method is being called every time some
action is being mapped to a method in this class so why not put the code for
checking  redirecting inside of prepare
like,
public void prepare() throws Exception
{
//if the user is not logged in
//redirect to the login page
}

But the problem is that I cannot return any string (which I can specify as
result of type redirect-action in the struts.xml file)since this function
has return type void also I could not find any method to redirect forcibly.

So, my question is whether it is possible to redirect form any method which
has not been mapped as an action at all?
if it can be done then how to do it?

Any ideas regarding this problem would really help.
Thanks in advance



-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: how to redirect from prepare() method in struts 2

2009-01-24 Thread sagsai

Thank you Dave,
feel like have to spend some time reading some books (which I really hate to
do) on struts like struts 2 in action :-(



newton.dave wrote:
 
 It would be much cleaner to put that kind of logic into an interceptor 
 rather than in a prepare() method. It would cut down significantly on 
 code duplication.
 
 Dave
 
 sagsai wrote:
 Hello friends,
 I have very little experience in struts 2  I have this typical
 requirement
 where I feel that I have to redirect form the prepare() method when the
 user
 is not logged in (by checking whether some session entries present or
 not).
 Actually I am trying to avoid repetitive session checking  redirecting
 at
 the beginning of every action method, for example
 public String listUsers() throes Exception
 {
 //if (session.get(userType) != null 
 session.get(userType).equals(admin))
 //then show the result
//otherwise redirect to the login page
 }
 
 public String viewDetails() throes Exception
 {
 //again code for the same checking
 }
 so I thought that since the prepare() method is being called every time
 some
 action is being mapped to a method in this class so why not put the code
 for
 checking  redirecting inside of prepare
 like,
 public void prepare() throws Exception
 {
 //if the user is not logged in
 //redirect to the login page
 }
 
 But the problem is that I cannot return any string (which I can specify
 as
 result of type redirect-action in the struts.xml file)since this
 function
 has return type void also I could not find any method to redirect
 forcibly.
 
 So, my question is whether it is possible to redirect form any method
 which
 has not been mapped as an action at all?
 if it can be done then how to do it?
 
 Any ideas regarding this problem would really help.
 Thanks in advance
 
 
 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org
 
 
 

-- 
View this message in context: 
http://www.nabble.com/how-to-redirect-from-prepare%28%29-method-in-struts-2-tp21643785p21644051.html
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: how to redirect from prepare() method in struts 2

2009-01-24 Thread Dave Newton

sagsai wrote:

Thank you Dave,
feel like have to spend some time reading some books (which I really hate to
do) on struts like struts 2 in action :-(


The Struts 2 documentation wiki covers an awful lot of the frameworks, 
combined with the sample applications there's quite a bit of information 
available for free (and not on paper).


Dave


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: how to redirect from prepare() method in struts 2

2009-01-24 Thread sagsai

Thank you again,
You saved me a lot of pain :-)


newton.dave wrote:
 
 sagsai wrote:
 Thank you Dave,
 feel like have to spend some time reading some books (which I really hate
 to
 do) on struts like struts 2 in action :-(
 
 The Struts 2 documentation wiki covers an awful lot of the frameworks, 
 combined with the sample applications there's quite a bit of information 
 available for free (and not on paper).
 
 Dave
 
 
 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org
 
 
 

-- 
View this message in context: 
http://www.nabble.com/how-to-redirect-from-prepare%28%29-method-in-struts-2-tp21643785p21644192.html
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



RE: how to redirect from prepare() method in struts 2

2009-01-24 Thread Andy

Just got done reading Struts2 In Action and highly recommend it, as well as the 
documentation :)



 From: w...@wantii.com
 To: user@struts.apache.org
 Subject: Re: how to redirect from prepare() method in struts 2
 Date: Sat, 24 Jan 2009 14:48:53 -0500
 
 On Saturday 24 January 2009 14:11:44 Dave Newton wrote:
  sagsai wrote:
   Thank you Dave,
   feel like have to spend some time reading some books (which I really hate
   to do) on struts like struts 2 in action :-(
 
  The Struts 2 documentation wiki covers an awful lot of the frameworks,
  combined with the sample applications there's quite a bit of information
  available for free (and not on paper).
 
  Dave
 
 Awww... Come on, Dave... If the guy wants to buy a book, I don't see a 
 problem 
 with that!
 
 -Wes
 -- 
 
 Wes Wannemacher
 Author - Struts 2 In Practice 
 Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
 http://www.manning.com/wannemacher
 
 
 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org
 

_
Windows Liveā„¢: E-mail. Chat. Share. Get more ways to connect. 
http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_allup_howitworks_012009

Re: how to redirect from prepare() method in struts 2

2009-01-24 Thread Wes Wannemacher
On Saturday 24 January 2009 14:56:22 Andy wrote:
 Just got done reading Struts2 In Action and highly recommend it, as well as
 the documentation :)


I can say with confidence that the author is working hard to make the follow-
up a first class guide on some of the plugins like Conventions and Spring, as 
well as integrating s2.1 with things like JPA, JQuery, Sitemesh and many other 
things not covered in S2IA.

(Okay, I'll quit plugging now :) )

-Wes
-- 

Wes Wannemacher
Author - Struts 2 In Practice 
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: how to redirect from prepare() method in struts 2

2009-01-24 Thread stanlick
Wes is right Dave... if the guy wants to buy a book, who are we to
discourage it?  Your demand will not be affected in the least!  Also, I
would like to give a shout out to the upcoming Struts 2 in Practice book.  I
have been reviewing it, and it absolutely rocks!  Of course my boy Wes
learned everything about the framework from reading Struts 2 in Action.

Peace (and Words),
Scott

On Sat, Jan 24, 2009 at 2:38 PM, Wes Wannemacher w...@wantii.com wrote:

 On Saturday 24 January 2009 14:56:22 Andy wrote:
  Just got done reading Struts2 In Action and highly recommend it, as well
 as
  the documentation :)
 

 I can say with confidence that the author is working hard to make the
 follow-
 up a first class guide on some of the plugins like Conventions and Spring,
 as
 well as integrating s2.1 with things like JPA, JQuery, Sitemesh and many
 other
 things not covered in S2IA.

 (Okay, I'll quit plugging now :) )

 -Wes
 --

 Wes Wannemacher
 Author - Struts 2 In Practice
 Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
 http://www.manning.com/wannemacher


 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org




Re: how to redirect from prepare() method in struts 2

2009-01-24 Thread Dave Newton
The guy specifically said he wasn't psyched about reading a book. I 
provided alternatives. Life goes on.


stanl...@gmail.com wrote:

Wes is right Dave... if the guy wants to buy a book, who are we to
discourage it?  Your demand will not be affected in the least!  Also, I
would like to give a shout out to the upcoming Struts 2 in Practice book.  I
have been reviewing it, and it absolutely rocks!  Of course my boy Wes
learned everything about the framework from reading Struts 2 in Action.

Peace (and Words),
Scott

On Sat, Jan 24, 2009 at 2:38 PM, Wes Wannemacher w...@wantii.com wrote:


On Saturday 24 January 2009 14:56:22 Andy wrote:

Just got done reading Struts2 In Action and highly recommend it, as well

as

the documentation :)


I can say with confidence that the author is working hard to make the
follow-
up a first class guide on some of the plugins like Conventions and Spring,
as
well as integrating s2.1 with things like JPA, JQuery, Sitemesh and many
other
things not covered in S2IA.

(Okay, I'll quit plugging now :) )

-Wes
--

Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org







-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: how to redirect from prepare() method in struts 2

2009-01-24 Thread stanlick
Can I ask a personal question Dave?  Does this have anything to do with your
illiteracy? :)

P.S. And why are you not finishing your leather bound volume?  I already
said I would pay in advance!

On Sat, Jan 24, 2009 at 3:28 PM, Dave Newton newton.d...@yahoo.com wrote:

 The guy specifically said he wasn't psyched about reading a book. I
 provided alternatives. Life goes on.


 stanl...@gmail.com wrote:

 Wes is right Dave... if the guy wants to buy a book, who are we to
 discourage it?  Your demand will not be affected in the least!  Also, I
 would like to give a shout out to the upcoming Struts 2 in Practice book.
  I
 have been reviewing it, and it absolutely rocks!  Of course my boy Wes
 learned everything about the framework from reading Struts 2 in Action.

 Peace (and Words),
 Scott

 On Sat, Jan 24, 2009 at 2:38 PM, Wes Wannemacher w...@wantii.com wrote:

  On Saturday 24 January 2009 14:56:22 Andy wrote:

 Just got done reading Struts2 In Action and highly recommend it, as well

 as

 the documentation :)

  I can say with confidence that the author is working hard to make the
 follow-
 up a first class guide on some of the plugins like Conventions and
 Spring,
 as
 well as integrating s2.1 with things like JPA, JQuery, Sitemesh and many
 other
 things not covered in S2IA.

 (Okay, I'll quit plugging now :) )

 -Wes
 --

 Wes Wannemacher
 Author - Struts 2 In Practice
 Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
 http://www.manning.com/wannemacher


 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org





 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org




Re: how to redirect from prepare() method in struts 2

2009-01-24 Thread Wes Wannemacher
On Saturday 24 January 2009 17:05:04 stanl...@gmail.com wrote:

 P.S. And why are you not finishing your leather bound volume?  I already
 said I would pay in advance!


http://www.packtpub.com/apache-struts-2-web-application-development-beginners-
guide/book

/Speaking of buying books :)

I feel so dirty, now, having plugged my own book while Dave showed restraint 
and did the right thing :)

-Wes

-- 

Wes Wannemacher
Author - Struts 2 In Practice 
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: how to redirect from prepare() method in struts 2

2009-01-24 Thread Wes Wannemacher
On Saturday 24 January 2009 17:05:04 stanl...@gmail.com wrote:
 Can I ask a personal question Dave?  Does this have anything to do with
 your illiteracy? :)

 P.S. And why are you not finishing your leather bound volume?  I already
 said I would pay in advance!


On that same page...

Dave, did you write your own bio? Or, did you flame the database guy at Packt 
on this very list 

quote - 

He's a regular (if crabby) fixture on the Struts user mailing list, prodding 
people to read the documentation and think outside the box.

-- 

Wes Wannemacher
Author - Struts 2 In Practice 
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: how to redirect from prepare() method in struts 2

2009-01-24 Thread Dave Newton

Wes Wannemacher wrote:

On Saturday 24 January 2009 17:05:04 stanl...@gmail.com wrote:

P.S. And why are you not finishing your leather bound volume?  I already
said I would pay in advance!


Believe me--I've been trying :| It's been an... interesting process.


Dave, did you write your own bio?


How could you tell?

He's a regular (if crabby) fixture on the Struts user mailing list, prodding 
people to read the documentation and think outside the box.


Oh, that's how. I also snuck in a few Oh, snap!s up in thay-ure.

Dave


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org