Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!

Meera Godse

Greenhorn
+ Follow
since Jan 09, 2007
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Meera Godse

"You can also use a combination of rules defined using the validator framework and your own validation in the validate method (be sure to call super.validate())."



How to do that ? I have already posted this as a separate thread but i am not getting any response on that. There are a few instances in my code where i must write my own javascript methods in addition to the ones supported by the validator. How & from where do I call these methods ? Onsubmit option is ruled out as the validator uses that. So how do I call my own methods which i want to be called say after the validator methods end ? pls help .
13 years ago

"we have javascript validation for client side.
we have got validate method in ActionForm class.
and Validator framework. why so different types for validation."



Hi Shreenivas, I am new to validator framework myself, so this wont be the experts opinion but heres my explanation...
The validator helps us to automate the client &/or server side validations. In case of client-side validations, if you implement the validator, it will generate all the javascript for you instead of you having to code in javascript. This saves your time & effort and for any future changes, its easy to modify the config & xml files.

For server-side validation, one way is to write the code in the validate method of form-bean. But again, if you use the validator, the form-bean class must extend ValidatorForm class (or DynaValidatorForm and so on), which automatically creates the validate method for you. so you do not need to code for the validate method yourself.

So, you can use any of the option you like for your code. I hope this was helpful.
- Meera.
13 years ago
Forgot to mention ...... Results are as per Firefox Mozilla.
13 years ago
Hi,
I am facing a problem with validator framework. I have 2 sets of fields - one for billing address and one for shipping address. By default both values are the same & hence all the textboxes under the shipping address (like addr,city,state,...) display the values but are disabled/readonly.
A checkbox with label "Same as billing address" can be selected/deselected by the user. When the checkbox is deselected, all textboxes are enabled for the user to input the correct address.
Now heres my problem -

I am using client-side validation. When the textboxes are in readonly state & I try to submit the form, the validation rules (of 'required','mask','integer' etc) are getting called ,although data is present in the textbox. Why cant it detect the data in the textboxes if they are marked readonly ? what is the solution ?
Pls advice.
13 years ago
I am not quite clear with the example provided. Is 'ValidationUtil' a simple class with this one method of validate fields ? Do I write my javascript methods in this class just the way I would write them down on my JSP ? Can i write multiple javascript methods here ? and how do i access the controls of JSP through this method (eg: I want to validate the array of objects. so how can i access each textbox control ?)

Just a wild thought .... can we use the validate method of the form-bean in any way, for using my own javascript methods ?
13 years ago
thank you for your response.
Isnt there any other way to do it ? I want my methods to be called after all the validator methods have been called. Right at the end. For an onclick event, these methods will be called first & then the validator ones will be executed.
Is there no way, i can write both validator methods & my methods without these problems ? Validator is unable to provide my requirement , so I must write my own methods along with the validator ones.
pls help
13 years ago
Hi,
How do I use struts validator and my own javascript functions at the same time ? Right now because I am using the validator for client-side validations, i write the onsubmit as "return validateFormName(this)". For the checks not included by the struts validator, how do i call my own javascript methods ? please help.
13 years ago
How do I use struts validator and my own javascript functions at the same time ? Right now because I am using the validator for client-side validations, i write the onsubmit as "return validateFormName(this)". For the checks not included by the struts validator (like the one discussed above), how do i call my own javascript methods ? please help.
13 years ago
thank you merrill. i will write my own javascript for this case. One more query. Just like we have a rule for validation of 'email' do we have a check to validate the pathname specified for the html:file control ? The form gets submitted even if i enter some junk characters as abc^&*xy
13 years ago
Hi,
I am facing a problem with validator. I intent to use client side validation & I am unable to write the declarations in the validation.xml file for the following:

My form bean has an array as : private Spec[] specs = new Spec[10];
where Spec contains 2 String fields param and value. So on the JSP, i see an array of textboxes for Param and Value. I want to check if value has been entered for atleast one param-value pair. How do i check this using validator ?
in my jsp, they are declared as:

<tr><td>Srno.</td><td>Parameter</td><td>Value</td></tr>
<% int i=0; %>
<logic:iterate name="productForm" id="specs" property="specs">
<tr>
<td><%=(++i)%></td>
<td><html:text name="specs" property="param" indexed="true" /></td>
<td><html:text name="specs" property="val" indexed="true" /></td>
</tr>
</logic:iterate>

any help is appreciated. thanks.
13 years ago
thank you merrill. things are clear now.
13 years ago
oh got it.
I am a bit confused. If i use both the declarations in my jsp file (html:errors and javascript tag with onsubmit), which one will get evaluated ? Also, if there is a (server side)validation like say, check for the entered value to the one in database & then give message to user, how is that handled using validator ? how is a error message rendered in such a case ?
13 years ago
For one form-bean, i forgot to change the 'extends' value from ActionForm to ValidatorForm. The client-side struts validations still seem to work ! the alert box pops up with the error message. Isnt it mandatory to use ValidatorForm (or ValidatorActionForm etc) for a form bean ?
13 years ago
Thank you Merrill for all the help. I greatly appreciate it. I had made 2 mistakes.
1. i was using my own validation-rules file that i had copied from the web instead of using the one inside struts jar. (i didnt know it comes with the jar)
2. my message resources file was placed under web-inf folder instead of web-inf/classes. I moved it to its right place & the msgs were displayed.

Brent, this is a project i am doing on my own from scratch just to learn struts. so it has always been struts 1.3.5 from start. I tried the code with both <arg0> & the position parameter & they both work.
The link you mentioned was quite informative. thank you.

So the only difference between client & server side validation is the use of html:errors & javascript tag, is it ? So do we use struts client side validations to avoid using javascript directly ?
13 years ago
ok. i changed the plug-in declaration and now i am using all the files from struts 1.3.5.
it still doesnt show me the messages. validations seem to get bypassed & the action executes.
13 years ago