aspose file tools*
The moose likes Struts and the fly likes validation - depends on the circumstances Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "validation - depends on the circumstances " Watch "validation - depends on the circumstances " New topic
Author

validation - depends on the circumstances

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Hi there,
I have a form with 3 buttons:
1. clear - clears the form
2. cancel - go to main page
3. submit - do some business

the forms needs to be validated therefore the validator on the struts-config.xml is set to true.

but when the user clicks cancel - there's nothing to check!
So how can I make sure that cancel & clear will 'cancel' the validation process.

thanks
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If you use an <html:clear> tag, no submit is done, so no validation will be done. If you use an <html:cancel> tag, a submit will be done, but Struts will automatically skip validation for this tag.


Merrill
Consultant, Sima Solutions
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
thanks Merrill,

the cancel works, thanks.

I wonder how to have it as an icon (not button) I tried:
but it didn't work out.

the 'clear' for some reason didn't work for me. I get a red line below the tag:
<html:clear>; and I have the tag ref as: struts-html-el.tld (EL??!?!?)


Regardless, when I click submit and fill all relevant fields, I realize that the relevant field becomes empty and the error message kicks in (ABC is required field)

Wonder why it doesn't take the information I provided.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Sorry for the confusion. There is no <htm:clear> tag. I was thinking of the <html:reset> tag. If the JSP page started out blank, a reset button will essentially clear all the fields without submitting the form.

As far as using an image goes, Just use the <html:image> tag and specify property="<%=org.apache.struts.taglib.html.Constants.CANCEL_PROPERTY %>". This will accomplish the same thing as the <html:cancel> tag.
[ October 23, 2006: Message edited by: Merrill Higginson ]
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
thanks Merrill.

Q1: I tried this (as instructed):

which didn't work - I get this message:

I wonder if I'm missing any file?

Q2: what about the reset and the submit buttons, what will their property (assuming it'll work) should be if I'm intrested using images.?

I looked at the docs, and the properties for constants are:
Bean, cancel, form, select and token.

thanks again for all the help.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Change your taglib declaration to use the regular struts-html tag library instead of struts-html-el.
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
thanks this worked out.

the only thing left is the <html:reset>

what is the property of the reset. the cancel is:


so I can do this:


but when it comes to the reset there is no Contants.RESET_PROPERTY?
(I though of creating my own property & value and then look it up in the execute Action, but that will not work out because validation will take place)

thanks
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Since the reset button doesn't submit, you can just use a regular <img> tag with JavaScript:

<img src="images/mybutton.gif" onklick="document.forms[0].reset()" />
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
i tried the following combinations, none worked.

in my aplc i used onClick (not on_Click)

in the first 4 - the icon is unpressable
and the last 2 - error message:



Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The correct attribute is "onclick" .. all lower case. Sorry about the confusion, but that #$#%9 JavaRanch filter won't let me enter it correctly in context. I know the example I gave you works on both Firefox and and Internet Explorer.
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
mmm....even with this or other combination it doesn't work
tried onclick (all lower case)
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
There is no "javascript:". Type it exactly the way I did in my first post, replacing the "k" with a "c" in onclick. I know for sure that it works, because I tried it myself in two different browsers.

<img src="images/mybutton.gif" onklick="document.forms[0].reset()" />

If this doesn't work for you, it may be that you have JavaScript turned off on your browser.
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Thanks,

is there anything else I need to mention in my jsp page (maybe <script> ) that I'm about to use javascript.

I tried the code below (onclick, lowercase no :javascript) and although I can see the image, it's simply unclickable.

my javascript is enabled (I tested it with a simple html file with alert...and it was working)

thanks Merrill for your genuine help


Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
When you say "it's simply unclickable", what do you mean?

Nothing is unclickiable on an html page. There's nothing to stop you from clicking on something. If you mean that the cursor style doesn't change to a pointing finger, that's expected. We've done nothing to change the cursor style for this object, but that doesn't stop you from being able to click on it and it doesn't stop it from working once you do click on it. If you want the cursor style to change as it does for the other buttons, here's how you'd code it:

<img src="images/myImage.gif" style="cursor:pointer" onklick="document.forms[0].reset()" >

It also may not be clear to you how to test if this is working or not. If the server displays the page and an input field is blank, enter some data in that input field and then click on the reset image. If the field becomes blank, the button is working.
[ October 25, 2006: Message edited by: Merrill Higginson ]
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Merrill,

After so much extensive research today, I still didn't solve the problem.
I am aware of the reset functionality and I'm checking it against some data (to see if it clears it)

I added the style="cursor ointer" and YES it shows the pointer...but still nothing happens.

I'm attaching my code here (the problem is marked with <!----- PROBLEMATIC BUTTON --> maybe something will catch your eye.

thanks again

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The only thing I can think of is that perhaps this page is part of a composite page. If that is the case, this code might not work, because I'm assuming that that the form you're resetting is the first and only one on the page. If this is part of a composite page, this may not be the case.


Try changing the javascript so that it uses the form name instead of forms[0]. In Struts, the html form name will always be the same as the name attribute used in the action mapping. In your case, look at the name attribute in the action mapping for /groupProposal and use that name in the javascript.

So, if the name happens to be groupProposalForm, use this code in the onclick:

document.groupProposalForm.reset()

instead of

document.forms[0].reset()
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Merrill,

Finally!!! thanks for all the answers and determination!

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: validation - depends on the circumstances
 
Similar Threads
problem using validator framework with DispatchAction
LookupDispatchAction + html:cancel
Cancel button and bypassing JavaScript validation
Newbie no validation on Cancel button click.
Avoiding validation when hitting the Cancel button