Struts validator is not working

J

Johan

I really need some help. I´m a beginner at Struts and have run in to
some trouble with the validator framework. The problem is simply that
no validation takes place at all. I guess that I´ve missed something
in my configuration so I will show you some of the code I´ve written.
I would be really nice if someone more expirienced than I would like
to take a look at it. When Tomcat boots up I can see at the console
somethin like "validatorPlugIn initResources ...Loading validation
rules from /WEB-INF/validator-rules.xml" . A little bit further down
can a see "..Adding Formset ".. etc.. so I dont think it is a problem
with the validator-init.

So why is there no validation done before the form is submitted to the
Action class, that is my question?

#-- First the struts-config.xml
<struts-config>
<form-beans>
<form-bean
name="guestBookForm"
type="GuestBookForm">
</form-bean>
</form-beans>

<action-mappings>
<action
path="/GuestBookAction"
type="GuestBookAction"
name="guestBookForm"
scope="request"
validate="true"
input="/guestbookview.jsp"........
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/validator-rules.xml,

/WEB-INF/validation.xml"/>
</plug-in>
.......

#-- The validation.xml

<form-validation>
<formset>
<form name="guestBookForm">
<field
property="name"
depends="required">
<arg0 key="label.name"/>
</field>
<field
property="msg"
depends="required">
<arg0 key="label.msg"/>
</field>
</form>
</formset>
</form-validation>

#-- The JSP page where the form picks up the data guestbookview.jsp
.....
<logic:messagesPresent>

<html:messages id="error">
<li><c:eek:ut value="${error}"/></li>
</html:messages>

</logic:messagesPresent>
<body>
<html:form action="GuestBookAction.do?action=add">
Name:
<html:text property="name"/><br>
Homepage:
<html:text property="homepage"/><br>
Messege:
<html:textarea property="msg"/><br>
<html:submit><bean:message
key="button.guestbook.submit"/></html:submit>
</html:form>
......

#-- And the ValidatorActionForm GuestBookForm.java

import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.validator.ValidatorActionForm;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;

public class GuestBookForm extends ValidatorActionForm{
private String name;
private String homepage;
private String msg;

public void setName(String name) {
this.name=name;
}
public String getName() {
return name;
}
public void setHomepage(String homepage) {
this.homepage=homepage;
}
public String getHomepage() {
return homepage;
}
public void setMsg(String msg) {
this.msg=msg;
}
public String getMsg() {
return msg;
}
}
 
S

Sudsy

Johan said:
I really need some help. I´m a beginner at Struts and have run in to
some trouble with the validator framework. The problem is simply that
no validation takes place at all. I guess that I´ve missed something
in my configuration so I will show you some of the code I´ve written.
I would be really nice if someone more expirienced than I would like
to take a look at it. When Tomcat boots up I can see at the console
somethin like "validatorPlugIn initResources ...Loading validation
rules from /WEB-INF/validator-rules.xml" . A little bit further down
can a see "..Adding Formset ".. etc.. so I dont think it is a problem
with the validator-init.
<snip>

While I don't have the time (if you don't have the money) to address
your problem directly, I can suggest an article I've written:
<http://www.sudsy.net/technology/validation.html>
Hope it helps!
 
R

Ryan Stewart

Johan said:
public class GuestBookForm extends ValidatorActionForm{

Try ValidatorForm rather than ValidatorActionForm. See the docs for the
difference.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top