aspose file tools*
The moose likes Struts and the fly likes Validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Validation" Watch "Validation" New topic
Author

Validation

Garandi Garandi
Ranch Hand

Joined: Jan 07, 2003
Posts: 192
Hi,
Q1:
How to validate a field if it is NOT blank; but if the field is BLANK just ignore it?
Q2:

The server side validation is working, but the client side does not work.
I have the following line of code in my jsp file
<html:form action="/contactInfoEdit" onsubmit="return validateContactInfoBean(this);">
How to make client side validation to work? do I have to add some line of code on my jsp or validation.xml?
Thank you in advance
Garandi
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Q1: If you are using the validation framework, it will already do this for you. Simply don't list required as a validation.

Q2: html:javascript tag and you should be all set.


A good workman is known by his tools.
Garandi Garandi
Ranch Hand

Joined: Jan 07, 2003
Posts: 192
Marc thank you for your reply, but I am new to struts and a bit confuse.

Q1: If you are using the validation framework, it will already do this for you. Simply don't list required as a validation.

I am using validation framework, and in validation.xml I have the following
lines.
<formset>

<form name="contactInfo">
<field property="zipCode"
depends="required">
<arg0 key="prompt.username"/>
</field>
</form>
</formset>
so you are saying just remove depends="required", but what it has to validate against?
The above xml says the zipCode field cannot be blank. But I want it, if it is not blank the validate it against zipCode validation rule.


Q2: html:javascript tag and you should be all set.

I have the following line of code in my jsp file, but still it does not kick client side validation.

<html:javascript formName="contactInfo"/>

the above line is in contact_info_edit.jsp file.
and in struts-config.xml file I have the following line.

<form-bean name="contactInfo" type="com.mycome.ContactInfoBean" />
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Q1: depends="yourZipCodeRule" and the method that this rule points to should do a check for null or empty string. If this method finds null or empty string it should return true but not add an error to ActionErrors.
Most custom methods you write for the validator framework should do this check.

Q2: Your onsubmit="return validateContactInfoBean(this);" should be:
onsubmit="return validateContactInfo(this);"
Garandi Garandi
Ranch Hand

Joined: Jan 07, 2003
Posts: 192
Thank you for your reply Marc.
But I still have problem with client side validation.


so in contact_info_edit.jsp file I have the following line.



although I did change it to onsubmit="return validateContactInfo(this);
But still it does not call javascript code it all.
I put an alert("tell me") but it does not get into javascript.
Thank you in advance.
Garandi Garandi
Ranch Hand

Joined: Jan 07, 2003
Posts: 192
Problem is resolved it should be as Marc said
onsubmit="return validateContactInfo(this);"

Thank you
Garandi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Validation
 
Similar Threads
Problem with validator-rules.xml JavaScript
Not able to understand some javascript written in validator-rules.xml
Error 'required' is undefined
Error while trying NewsLetter Example
Struts Validator FrameWork = JavaScript Error