• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to do "redirect-action" to some action from within ActionSupport?

 
Michael Brown
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hy,

Can , please, someone help me with this:

How can I do a "redirect-action" to some action from within ActionSupport ?

I want to write an ActionSupport class that will insert some data in the DB and if succeeds , I want to redirect to some action set in this ActionSupport ( an action name, as String, is provided in this ActionSupport class ) and if not, just go to error.jsp

Can this be done, and how would I map this action in a strut.xml file ?

something like this:

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'd define a "success" result of the "redirectAction" type.
 
Michael Brown
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, If I want to use struts.xml

But I want to create redirect-action within code of my ActionSupport class...

How to do that?

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why? There's almost never any reason to build a result dynamically in the code itself (and I suspect it's difficult enough to be impractical). What are you trying to do that you don't believe can't be done via normal means?
 
Michael Brown
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, I made a small mistake: I need just an ordinary "redirect" , not "redirect-action"

Why? There's almost never any reason to build a result dynamically in the code itself (and I suspect it's difficult enough to be impractical). What are you trying to do that you don't believe can't be done via normal means?


Let's say I have ActionSupport "a" whose view is "a.jsp" and on submit I "call" ActionSupport "b" that needs to insert some data in the DB and redirect to action "a" ( go to the beginning )

And what if I have N such "circles" for every table in the DB.
That way I would map N actions "a" + N actions "b" in the struts.xml

I want to make universal action "b" that will do the insertion of the data no matter how that data looks like , and redirect to some action that I specified in some String...
That way I don't need to map those N "b" actions in the struts.xml

This is just, of course, simplified version of what I'm doing...

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a dynamic result? You can use OGNL expressions in result declarations.

I don't understand what you're saying, though, and so far I don't see anything that would require generating dynamic configurations.
 
Michael Brown
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,

Thank you very much for your answers!
I appreciate it!

Use a dynamic result? You can use OGNL expressions in result declarations.


This sounds like a solution to my problems...

I'll give it a try!
 
Pavel Kazlou
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why writing to DB using struts ActionSupport? This class is used for request processing.
In your scenario ActionSupport B has no real meaning in terms of request. It just write something to DB.
So why don't you create DAO and use it inside your ActionSupport A to read/write from/to DB? I don't see any reason to using ActionSupport in such a strange manner.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Pavel: he said the DB work was being done from the action class, not how.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic