Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Struts and the fly likes Struts Validator does not validate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Validator does not validate" Watch "Struts Validator does not validate" New topic

Struts Validator does not validate

Larysa Martinez

Joined: Aug 27, 2007
Posts: 1
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) { = active;

In struts-config.xml :

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

<forward name="domainUpdate" path="/jsp/edit_domain.jsp" />

<forward name="domainUpdate" path="/jsp/edit_domain.jsp" />

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" />


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

<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN"

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

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


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:form action="/jsp/domainUpdate" onsubmit="return validateDomainUpdateForm(this);">
<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.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864

Please check your private messages.

Consultant, Sima Solutions
I agree. Here's the link:
subject: Struts Validator does not validate
It's not a secret anymore!