This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Struts Validator does not validate  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone, it's the first time when I use Struts Validator with an application, and maybe my mistake is a simple and foolish one, but I just can't figure it out. I have read a lot of examples using Struts Validator, searched on forums, tried everything I could thought of but...Maybe someone more experienced could help me. I have a form with just one field which must be filled and I must check if it's empty, his maximum and minimum length. I should better post the code and you'll see.

public class DomainUpdateForm extends ValidatorForm//handles the update and the add operation
{
private int id_domain;
private String domain_name;
private short active;

public String getDomain_name() {
return domain_name;
}
public void setDomain_name(String domain_name) {
this.domain_name = domain_name;
}
public int getId_domain() {
return id_domain;
}
public void setId_domain(int id_domain) {
this.id_domain = id_domain;
}
public String toString()
{
return id_domain+" "+domain_name;
}
public short isActive() {
return active;
}
public void setActive(short active) {
this.active = active;
}
}

In struts-config.xml :

<form-bean name="domainUpdateForm" type="DomainUpdateForm" />

<action
path="/jsp/domainUpdate"
type="DomainUpdateAction"
input="/jsp/edit_domain.jsp"
attribute="updateDomain"
name="domainUpdateForm"
scope="request"
validate="true">
<forward name="domainUpdate" path="/jsp/edit_domain.jsp" />
</action>

<action
path="/jsp/domainAdd"
type="DomainUpdateAction"
input="/jsp/edit_domain.jsp"
attribute="addDomain"
name="domainUpdateForm"
scope="request"
validate="true">
<forward name="domainUpdate" path="/jsp/edit_domain.jsp" />
</action>

There are two action mapping because the same form is used for adding a new domain name and for updating an existent one.

<message-resources parameter="ApplicationResources" />

<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
</plug-in>


validation.xml:

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_0.dtd">

<form-validation>
<formset>
<form name="domainUpdateForm">
<field property="domain_name" depends="required,minlength,maxlength">
<arg0 key="domain.domain_name"/>

<arg1 key="${var:minlength}"
name="minlength"
resource="false" />
<arg1 key="${var:maxlength}"
name="maxlength"
resource="false" />

<var>
<var-name>minlength</var-name>
<var-value>1</var-value>
</var>
<var>
<var-name>maxlength</var-name>
<var-value>20</var-value>
</var>
</field>
</form>
</formset>
</form-validation>


In ApplicationResources : (besides the rows that were already there by default) : domain.domain_name=Il faut remplir le nom de domaine!.

In the JSP file (edit_domain.jsp):
.....
.....
<html:errors/>
.....
<html:form action="/jsp/domainUpdate" onsubmit="return validateDomainUpdateForm(this);">
.....
</html:form>
<html:javascript formName="domainUpdateForm"/>



I quess that would be all that can interested you. The problem is that when I submit the form, if I do not fill in the field, meaning it is left empty, there is no error displayed. I should see the error message:"Il faut remplir le nom de domaine!"...and so I get empty fields stored in the database (. That's why I told you, that validation is not working. Does anyone have any idea why?
Thanks in advance.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Larysa,

Please check your private messages.
 
Uh oh, we're definitely being carded. Here, show him this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!