aspose file tools*
The moose likes Struts and the fly likes How to pass a dynamic parameter in struts-config.xml? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to pass a dynamic parameter in struts-config.xml?" Watch "How to pass a dynamic parameter in struts-config.xml?" New topic
Author

How to pass a dynamic parameter in struts-config.xml?

liang gu
Ranch Hand

Joined: Nov 05, 2001
Posts: 89
I have 2 actions specified in struts-config.xml, MyAction1 and MyAction2. If MyAction1 is successful, it generate a dynamic id. I need to pass this dynamic id to MyAction2 and forward to the URL: MyAction2.do?id=dynamicId. But I don't how to pass this dynamic id in struts-config.xml.
<action path="/MyAction1"
type="MyAction1Class">
<forward name="succeeded" path="/MyAction2"/>
<forward name="failed" path="/error.jsp"/>
</action>
Any solutions or suggestions to my problem? Thanks a lot.
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
The config file is loaded when the app is first started, so you will not be able to do it that way. You could add the id to a session in MyAction1 and then have MyAction2 pull the value from the session.
[ November 20, 2002: Message edited by: Matthew Phillips ]

Matthew Phillips
liang gu
Ranch Hand

Joined: Nov 05, 2001
Posts: 89
How about doing a response.forward() in MyAction1 class?
response.forward("MyAction2.do?id="+dynamicId);
I know that struts-config.xml is supposed to control the application. By doing response.forward(), it is kind of breaking the MVC model a little bit.
Liang
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
That would probably work, but why reinvent the wheel. Since MyAction1 is already going to forward to MyAction2 by returning an ActionForward, all you need to do is add the id to something that MyAction2 can access.
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
As I was reading Struts In Action I found another solution for you. It seems like it may be more appropriate to what you want to do.
liang gu
Ranch Hand

Joined: Nov 05, 2001
Posts: 89
Hi, Matthew:
The new solution you just gave is really and exactly what I needed. Thanks so much. And by the way, do you have a solution to the other post of mine?
------------------------------------------
I have two pages built by struts. The first page is the "add record" page. After click on "submit" button on this page, the request sent to the server, server then process "add record", then forward to a servlet to display the second page(if process is successful): the list of all records(including the one just added).
The problem I have now is that: if I refresh the second page(listing of all records), it will add another new record and then show the list of all records. Basically, when the page refreshed, the struts redo everything for the whole action(specifed in struts-config.xml), but all I want is only to refresh the list of all records. The following is part of my struts-config.xml I used:
<action path="/AddRecordCommit"
type="AddRecordCommitAction"
name="AddRecordForm"
scope="session"
input="/AllRecordList">
<forward name="succeeded" path="/servlet/showResultServlet"/>
<forward name="failed" path="/error.jsp"/>
</action>
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
Originally posted by liang gu:
Hi, Matthew:
The new solution you just gave is really and exactly what I needed. Thanks so much. And by the way, do you have a solution to the other post of mine?
------------------------------------------
I have two pages built by struts. The first page is the "add record" page. After click on "submit" button on this page, the request sent to the server, server then process "add record", then forward to a servlet to display the second page(if process is successful): the list of all records(including the one just added).
The problem I have now is that: if I refresh the second page(listing of all records), it will add another new record and then show the list of all records. Basically, when the page refreshed, the struts redo everything for the whole action(specifed in struts-config.xml), but all I want is only to refresh the list of all records. The following is part of my struts-config.xml I used:
<action path="/AddRecordCommit"
type="AddRecordCommitAction"
name="AddRecordForm"
scope="session"
input="/AllRecordList">
<forward name="succeeded" path="/servlet/showResultServlet"/>
<forward name="failed" path="/error.jsp"/>
</action>

I might have one idea, but I will have to look it up tonight. I will reply to that post if I what I am looking for.
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 566
Why do you guys want to use several lines of code for solving this when you can just put the information into the session or the request as an attribute, with only one line of code?


I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
 
jQuery in Action, 2nd edition
 
subject: How to pass a dynamic parameter in struts-config.xml?