This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Struts and the fly likes mentioning actions twice in struts-config Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Frameworks » Struts
Reply Bookmark "mentioning actions twice in struts-config" Watch "mentioning actions twice in struts-config" New topic
Author

mentioning actions twice in struts-config

Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

Hi all,

My specs suggest two actions for one JSP, may i know why should i write like that?

ex:

sample diagram is like this:

|----- showCustomerPaymentDataChangeStart.do
| |
fail |
| JSP Name here
| |
| |{logged_in}
| |
-------- CustomerPaymentDataChange.do


may i know what is the use of writing the actions twice in struts-config.xml file.

regards,
rahul
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Most JSPs require some sort of preparation before they can be displayed such as populating lists for dropdown boxes, getting user information from a database, etc. If the JSP contains an HTML form as most do, there is also an action that must be taken when the form is submitted. Hence, there is often a need for two actions for every JSP: One to prepare for the display of the JSP, and one to process the information entered by the user in an HTML form.


Merrill
Consultant, Sima Solutions
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

2 different actions - 2 different entries.


===Vyas Sanzgiri===
My Blog
Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

Originally posted by Merrill Higginson:
Most JSPs require some sort of preparation before they can be displayed such as populating lists for dropdown boxes, getting user information from a database, etc. If the JSP contains an HTML form as most do, there is also an action that must be taken when the form is submitted. Hence, there is often a need for two actions for every JSP: One to prepare for the display of the JSP, and one to process the information entered by the user in an HTML form.


can i get a simple example for this please?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Form bean:

Action classes:

struts-config.xml

ColorSelect.jsp

ColorResult.jsp

[ June 20, 2007: Message edited by: Merrill Higginson ]
Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

thanks alot Mr. Merrill Higginson
this example is a very good example

regards,
rahul
Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

found a problem in Mr. Merrill Higginson code.

after running this code implementing the back and next buttons.

when i use back button from the last jsp to privious jsp, the value I select from the list is not appearing.

May i know what should i do to solve this problem.

and the big question is if I have more than one list box which should always show the selected iteams whn i come back from the other pages i think this code has to be modified.

please suggest me
regards,

rahul
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Bear in mind that this code was written as a simple demo, not a complete application. It has no database persistence, which is something you'd naturally want to put in an actual application.

In order to have the value selected retained, you would have to actually save the value to a database and then retrieve it when the page is redisplayed. In the example, you would add the following lines to the PrepareColorAction class:

You'd then add the following code to the ProcessColorAction class:
Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

thank you very much Mr. Merrill Higginson for your indetailed reply.

And it seems we are supposed to create an onther class which gets and sets color. I think, even though UserDao is not a form bean it resembels like it.


Thnks and regards,
rahul
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: mentioning actions twice in struts-config
 
Similar Threads
logic:iterate not bean found
A Simple web application is this the correct way to use struts
Struts 1.2 session problem
IDE/Editor and STRUTS - Sue?
[Struts 2] Best practices for injecting EJBs into an action