Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validation

 
Garandi Garandi
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Garandi Garandi
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem is resolved it should be as Marc said
onsubmit="return validateContactInfo(this);"

Thank you
Garandi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic