This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
I am looking for validation on client side for struts. i have few fields which are mandatory and few only text or numbers etc(used html tag libraries)., however my users are impatient to fill all form fields and then recieve errors after submitting(the way struts validation framework works). I am using on onblur or onchange javascript functions can any one think of better solution using JSTL or Struts ( client side validation with out hitting the server again)
You should read about struts validation and the tag html:javascript.
Sri Anand
Ranch Hand
Joined: Mar 06, 2005
Posts: 392
posted
0
Thanks for the suggestion , my customers keep getting huge number of Fax which they input into html forms and they want instant error message like if a text field needs only number as input and they enter char by mistake they get instant message now ( achieved with java script onChange), with <html:javascript....> tag i get to show up alerts on clicking of submit is there way i can have more interactive validation with JSTL or Struts tags.. Hope i am clear enough with my requirement
Sri Anand
Ranch Hand
Joined: Mar 06, 2005
Posts: 392
posted
0
looks like i will never get any help on this forum ..ummm
looks like i will never get any help on this forum ..ummm
Dom Lassy has already replied to your question. If you want pertinent help, please state problems/requirements clearly.
You can give more 'interactive' messages through javascript. Dont use the struts validations, write your own javascript error handlers for those fields and use the onKeyPress() event (or something similar; I cant remember exactly) for your validation.
Sri Anand
Ranch Hand
Joined: Mar 06, 2005
Posts: 392
posted
0
Thanks!
Reply from Lassy really helped i got the struts client side validation working but what trouble i am facing is validating fields as soon as they are filled in ( which can be achieved through script funtions onBlur etc.,) but we have these validations frequently changing so i dont want to write lot of script and change that every time ..,
Can any one share their expertise ... on this if they have achieved this ...
Sri Anand
Ranch Hand
Joined: Mar 06, 2005
Posts: 392
posted
0
waiting for reply.. is this possible in struts .., or should go for JSF..
Sri Anand
Ranch Hand
Joined: Mar 06, 2005
Posts: 392
posted
0
I am really banging my head with struts... i am still waiting for some reply
One possible solution would be to define the validations in the xml file and include the <html:javaScript> tag. Then use your browser's "display source" function to see the JavaScript functions that Struts added to your JSP. You can then call those functions yourself in "onblur" events.
however i thought the client side javascript gets called on click of submit so not sure if we have options in struts ... to enable validation .. immediately on filling text field etc.,
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
posted
0
Originally posted by Raghunandan Mamidala: i thought the client side javascript gets called on click of submit
It does. However, the JavaScript functions are placed in your JSP and you can break out of the normal cycle and call them yourself in an onblur event if you want to. They will still get called at submit time, but they will always pass validation because you've already checked validations in an onblur event.
Sri Anand
Ranch Hand
Joined: Mar 06, 2005
Posts: 392
posted
0
Thanks for the help! I got it working
Sri Anand
Ranch Hand
Joined: Mar 06, 2005
Posts: 392
posted
0
I have declared following block of xml for requiredif validation
validation i intend here is lognumber is required, if appSource is Fax. other client side java scrit is working fine. I havent written any validation in validationrules.xml for requiredif and was expecting that this would be validated at server side but this didnt happen ?
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
posted
0
I think requiredIf is deprecated in later versions of Struts. I'd suggest you use validWhen instead. This link should explain how to use it. One thing you need to be aware of, though, is that neither requiredIf nor validWhen support client-side validation.
Sri Anand
Ranch Hand
Joined: Mar 06, 2005
Posts: 392
posted
0
We are using struts1.1 version plans of migration are bit far off for now, any Idea if there are issues in 1.1 version with requiredif
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.