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
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;
}
}
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
</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;
}
}