aspose file tools*
The moose likes Struts and the fly likes trapped in html:cancel tag ... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "trapped in html:cancel tag ..." Watch "trapped in html:cancel tag ..." New topic
Author

trapped in html:cancel tag ...

michelle Wang
Ranch Hand

Joined: Jan 12, 2004
Posts: 65
Hi,

I have an update form with a <html:cancel> button. The cancel action will succeed in going back to the previous page if all mandatory fields are filled with valid data (validation is done on the fields). But if any of these fields are filled with invalid data, pressing the cancel button will cause the validation to be performed.

Is this associated with the fact that my validation was done in action and not in actionform?

Is it possible to place validation, which requires database access, in the validate method of the actionform class? And how should I go about doing it? Can anyone provide sample code?


michelle Wang <br />SCJP 1.4
Srilakshmi Vara
Ranch Hand

Joined: Jul 21, 2004
Posts: 169
I have the same problem, then i changed from struts:cancel to ordinary cancel button. But according to the struts documentation cancel performs the action that is why your validation is getting activated ie., your cancel button is trying to call the action. You can check the documentation

http://struts.apache.org/userGuide/struts-html.html#cancel
michelle Wang
Ranch Hand

Joined: Jan 12, 2004
Posts: 65
thanks, Srilakshmi Vara .
But May I know what's the code of your normal button?
I only know use this:
history.go(-1)

The history.go(-1) is not stable also, if have many invalide submision, it can not work properly.
michelle Wang
Ranch Hand

Joined: Jan 12, 2004
Posts: 65
Any one can help? I still struggling with the cancel button....
Any one can provite working sample code? Thanks!!
Srilakshmi Vara
Ranch Hand

Joined: Jul 21, 2004
Posts: 169
Hi Michelle,

Use html:button instead of html:cancel name it with cancel and use the following javascript on onclick event of cancel button

function formCancel() {
var agree = confirm("You are about to exit this window and all the information on this page will be lost. Do you want to proceed?");
if(agree) {
window.opener.top.main.location.href = window.opener.top.main.location.href;
window.close();
} else {
return false;
}
}

I think this will help you

Srilakshmi
michelle Wang
Ranch Hand

Joined: Jan 12, 2004
Posts: 65
Hi, Srilakshmi Vara :
Thanks for ur help, I just tried to apply to my code, but hit this javascript error:

Char:3
Code:0
Error:'window.opener.top' is null or not an object
Sorry, I'm poor in javascript...
and btw, this line looks strange to me:
window.opener.top.main.location.href = window.opener.top.main.location.href;
Isn't it's both sides are the same?
[ June 21, 2005: Message edited by: michelle Wang ]
Srilakshmi Vara
Ranch Hand

Joined: Jul 21, 2004
Posts: 169
If you a project window and a child window The function i gave closes the child window and refreshes the project window.

This line is to refresh the project window, it is specific to my project remove this

window.opener.top.main.location.href = window.opener.top.main.location.href;


So remove the above line and try to execute the code it works.

If you still have problems, Let me know what type of action you want on clicking the cancel button.

Srilakshmi
michelle Wang
Ranch Hand

Joined: Jan 12, 2004
Posts: 65
Hi, Srilakshmi :
I think the code is not suitable for my case.. I only have 1 window, the first page is an search condition, then second page is a result list by the search condition, this second page has a "create new" button, When i click on the button will go to the create new page, now the "cancel" button come out, it is in the create new page, when I click "cancel" here , it should go back to the list(the second page). But now the pbm is bcs the list is retrieve from DB and based on the first page's search condition.. How to make it display again when I cancel from the third page?
Hope you understand what I mean, Thanks a lot.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: trapped in html:cancel tag ...
 
Similar Threads
Avoiding validation when hitting the Cancel button
calling reset on the form bean
LookupDispatchAction + html:cancel
Bypass client-side struts validation
Reset the form to Null or Reload the page using reset even after a submit