• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

My First Struts App

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am writing my first Struts application. I have a form that has a drop-down box, two text fields, a 'Continue' button, and a 'Clear' button. The user makes a selection from the drop-down, and then enters information in the two text fields. When they click the 'Continue' button, they are taken to an intermediate page where their selection and information is presented for confirmation. On that page their is a 'Submit' button and a 'Cancel' button. The 'Cancel' button is an <html:button> tag with an onclick attribute that is assigned 'window.location.href='firstPage'. If the user clicks on the 'Cancel' button, they are taken to the initial page where they made the selection and entered their information. The problem that I am encountering is that once they are on that page, if they decide to reset the field values and they click on the 'Clear' button, the fields do not clear. The 'Clear' button is an <html:reset> button. I have tried using the regual html <input type="reset" value="Clear" /> button, but I get the same results.

As long as the user does not click 'Continue' on the intial page, the 'Clear' button ( <html:reset> ) works; the problem comes if they go to the next page, realize they made a mistake and go back using the 'Cancel' <html:button value="Cancel" onklick="window.location.href='firstPage'"> (not using the back button).

As I was writing this post I remembered that I commented out the reset(ActionMapping mapping, HttpServletRequest request) function in the Action Form. The reason I did so was because the values were not being held from one page to the next, even though I specified a session scope in the struts-config.xml. So that may be why the 'Clear' button wouldn't work if I use the <html:reset> button, but I still don't understand why the 'Clear' button doesn't work if I use the regular html <input type="reset" value="Clear" />.

I hope this wasn't confusing. Any help would be greatly appreciated.

lugos

[ July 31, 2006: Message edited by: Samuel Lugo ]
[ July 31, 2006: Message edited by: Samuel Lugo ]
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The function of a reset button is to reset the data as it appeared when the page was first displayed before the user changed anything, or what I'll refer to as it's "base state".

The trouble with your logic is that when you display firstPage.jsp for the second time, you have redifined the base state. Base state now consists of the page as it appeared when you displayed it the second time. If the user enters information and presses reset, it will return to this base state, not the state it was in when you displayed it the first time.

If you want the page to appear as though it were the first time, change the button from a reset button to just a regular button. Then in the onclick event of that button, specify

this.form.action='myAction.do';this.form.submit()

where "myAction.do" represents the action that you called to display the page the first time.
 
Samuel Lugo
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Merrill,

Thank you for your response. I tried the solution that you suggested, but it still does not clear the information. Could it be that the ActionForm is retaining the data? Could it be because the scope is set to session?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make sure that in your Action class that displays the page for the first time, you set all properties of the ActionForm bean to blanks or default values.
 
Samuel Lugo
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean using the reset function from the ActionForm class? Because if so, I have that function commented out. The reason I do is because when it is not commented out, the data is not being passed from the intial JSP to the next JSP when I click submit. In between those two JSPs, I have another Action class that is used to do some error checking. If no errors are encountered, then they Action class forwards to the next JSP where the data is then displayed.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, that's not what I mean.

In the execute method of your action class, code:

myFormBean.setFoo("");
myFormBean.setBar("");

Do this for each of the properties in the bean.
 
Samuel Lugo
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I got it to work. Thank you for your assistance and your patience Merrill.
 
reply
    Bookmark Topic Watch Topic
  • New Topic