wood burning stoves 2.0*
The moose likes Struts and the fly likes Preventing submit of html:cancel using javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Preventing submit of html:cancel using javascript" Watch "Preventing submit of html:cancel using javascript" New topic
Author

Preventing submit of html:cancel using javascript

Charanjit Sidhu
Greenhorn

Joined: Apr 04, 2005
Posts: 13
Hi All,

I have a small problem.. I have a button named 'Make Changes' on which I just want to use the browser back functionality. But I am not able to do it. The button is:

<html:cancel onClic="fnGoBac()" > Make Changes </html:cancel >

and the javascript code is:

function fnGoBack()
{
alet("In fnGoBack")
histori.go(-1)
}

(Note: history,onClick and alert are misspelled as histori,onClic and alet so that I can post this on this site.)
Onclick the alert appears but instead of going back to previous page, I get the page as defined by the action associated with this page.

However if I change the button code to normal html code (as shown below), it works fine.. but for consistency sake, I want to follow all sturts html
tags..

<input type="button" value="Make Changes" onclic="fnGoBack()" >

Please let me know how can I achieve this by using Struts HTML:Cancel or some other tag..


Charanjit Sidhu<br />SCJP 81%
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30076
    
149

Charanjit,
You want to use html:button instead of html:cancel. Struts' cancel button maps to a submit button. It then has all the characteristics of a submit button - submitting the page, doing an action, etc. On the other hand, html:button renders into the input button type that you used in the HTML code sample.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Anant Rao
Ranch Hand

Joined: Nov 12, 2004
Posts: 126
Use
> html:button value="Back" property="Back" onclic="return OnButtonClick();"<>/html:button<

This might work for you.

Regards
Infyniti.
Kamesh Loganathan
Greenhorn

Joined: Jan 21, 2006
Posts: 20
Hi,
I think that a more refined way of doing this is to use the html:cancel button, no java script and check for iscancelled in the action and fwd appropriately to the previous page.

Using javascripts history looks to be crude to me.
Correct me if i am wrong.
Charanjit Sidhu
Greenhorn

Joined: Apr 04, 2005
Posts: 13
Thanks everybody for your responses.

I implemented the solution as suggested by Jeanne & Infyniti and it worked for me.

Kamlesh,
I just needed to show the previous screen with all the user's input in it. So I just used 'browser back functionality' for this purpose.
Actually I am learning Struts and didn't know how to repopulate the screen with same form data which had rows of input data having select and input boxes in each row. So I thought the quickest way will be to just do a 'Browser back'.

Thanks again!!
Charanjit
java_professional
Greenhorn

Joined: May 09, 2005
Posts: 1
I have a better implementation of the cancel button. You can actually use EL and send a hidden field of ${header.Referer} which refers to the previous page and then submit the page to that value.
Hope this helps!
-K
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Preventing submit of html:cancel using javascript
 
Similar Threads
want to display text link for html:cancel instead of button
Prevent the page refreshing
Problem in action servlet?
Problrm in calling userdefined method in onclick event of button dynamically
create a link for html:cancel instead of display button