aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Validator does not validate" Watch "Struts Validator does not validate" New topic
Author

Struts Validator does not validate

Larysa Martinez
Greenhorn

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) {
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.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Larysa,

Please check your private messages.


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts Validator does not validate
 
Similar Threads
Struts Validation not working
STRUTS: client-side validation in jsp using DynaValidatorForm
why does my application not perform server side validations?
Struts Validator Framework error
WARNING: REsource org/apache/struts/ validator/ LocalStrings_en_US.properties Not Fo