• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

returning user defined strings in Struts 2 action classes

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
How can i achieve the following?
As we know Struts 2 action classes have an execute method which returns a string.In my action class execute method, I call a method which returns a page name as a string.. the page name will be different as per the business logic.

How can i return the page string and map it in struts.xml ?

Thanks in advance.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure I understand your problem. Struts doesn't care what you return from execute as long as it matches a result in struts.xml and Struts doesn't care what you name results.
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rajiv,

Yes, you can return dynamic pages from your struts 2 action. The idea here would be to save the page name in an instance variable in the action, and create a getter/setter for it. Then in your action mapping, you can use the above created getter for your page name.

I created some quickie dummy actions and results just for elaboration purpose. So the naming might look a little bit eerie. Just bear with it.

Check out the following code for the action class.


I will be invoking the "anotherMethod" function in my action mapping that follows. If you wish to, you can use the the code written in the "anotherMethod" function inside the execute method itself.
Here's the action mapping.



As you can see, i returned a "success" string from my "anotherMethod" in the action class. So, the above result will be invoked on completion of the action. The page to be displayed is evaluated as an EL variable and fetches the nextPage property on the DummyAction2 class
The action invocation is just as usual.



I guess, you can let your business logic determine the page name. And you page will be displayed accordingly based upon the value set in a field in the action.

Hope this helps ;)

Regards,
Ryan Sukale
 
I think he's gonna try to grab my monkey. Do we have a monkey outfit for this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic