aspose file tools*
The moose likes Struts and the fly likes Implementing clear button in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Implementing clear button in struts" Watch "Implementing clear button in struts" New topic
Author

Implementing clear button in struts

Sunitha Mudidani
Greenhorn

Joined: Apr 25, 2006
Posts: 28
Hi all,
I have a jsp where some of the fields like "submitted date" have default values populated in the jsp. When the user clicks on the CLEAR button all the fields shd be cleared and the default fields shd be populated with teh default values.

I understand this can be implemented using a javascript function. But a session variable also has to be removed from the session scope on clicking this CLEAR button. Pls let me know how this can be implemented.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
One possible solution would be to use the <html:cancel> button. This button performs a submit, but does not call validation.

Once the form has been submitted, in your Action class you would call the superclass' isCancelled() method to determine whether the cancel button was pressed or not. If it was, you can do whatever you need to do to make the page appear as you want it to appear and to remove the session attribute.

If you're using Struts 1.2.9 or above, you will also have to add cancellable="true" to your action mapping.
[ March 05, 2007: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Sunitha Mudidani
Greenhorn

Joined: Apr 25, 2006
Posts: 28
Thanks for your reply.

But iam stuck in using the <html:cancel> button.
Iam using jdeveloper studioo version 10.1.3
Iam not sure which version of struts it is using.

When iam clicking on the CANCEL button no effect is taking place.
These are the changes that i have done.

1) In the JSP



2)In the struts-config.xml, added the below line in <action..> tag



3) In the Action class, the corresponding code is,

Also Iam getting an exception :





Pls let me know how to proceed

Thanks,
Sunitha
Sunitha Mudidani
Greenhorn

Joined: Apr 25, 2006
Posts: 28
The struts version being used in JdeveloperStudioVersion 10.1.3 is struts 1.1 So I removed the cancellable property and the exception is gone.

But the clear button implementation is not getting invoked.

Waiting for suggestions...
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Did you specify a property attribute in your <html:cancel> tag? If so, remove it. This will cause the isCancelled() method not to work.
Sunitha Mudidani
Greenhorn

Joined: Apr 25, 2006
Posts: 28
No.. I didnot use property attribute in <html:cancel>
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Please be more clear about what is happening. Is the execute of the action class being called when the cancel button is pressed? if so, is the value returned by isCancelled(request) false?
 
 
subject: Implementing clear button in struts