Hello,
I cannot seem to get the validator to plug args into my messages.
Everything else works (LogonForm.java/LogonAction.java,...).
When I run this basic test and click Submit with 3 empty fields, I get: {0} is
required!{0} is required!{0} is required!
Maybe somebody could kindly point out something obvious that I
missed/don't (yet) get?!
Thanks --Mike
environment:
Struts 1.2.4, Tomcat 5.0.28
struts-config.xml:
</struts-config> ......
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/validator-rules.xml, /WEB-INF/validation.xml"/>
</plug-in>
</struts-config>
ApplicationResources.properties:
......
index.msg.username=User name
index.msg.password=Password
index.msg.group=Group
errors.required={0} is required!
LogonForm.java:
...... getters/setters ......
public ActionErrors validate(ActionMapping mapping, HttpServletRequest
request) {
if (username.equals("user") && password.equals("pass") &&
group.equals("test")) {
System.out.println("You may proceed with caution"); //console
return null;
} else { // the compiler tosses -deprecation errors but ActionErrors
works (as opposed to ActionMessages...)
ActionErrors errors = new ActionErrors();
if ( getUsername() == null || getUsername().length() < 1 ) {
errors.add("username",new ActionError("errors.required")); }
if ( getPassword() == null || getPassword().length() < 1 ) {
errors.add("password",new ActionError("errors.required")); }
if ( getGroup() == null || getGroup().length() < 1 ) {
errors.add("group",new ActionError("errors.required")); }
System.out.println("Your form submission has been rejected."); //console
return errors; }}}
validator-rules.xml:
<form-validation>
<global>
<validator name="required"
classname="org.apache.struts.validator.FieldChecks"
method="validateRequired"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
msg="errors.required"/>
......
</global>
</form-validation>
validation.xml:
<form-validation>
<global />
<formset>
<form name="logonForm">
<field property="username" depends="required">
<arg0 key="User name" resource="false"/>
</field>
<field property="password" depends="required">
<arg0 key="index.msg.password"/>
</field>
<field property="group" depends="required">
<arg0 key="index.msg.group"/>
</field>
</form>
</formset>
</form-validation>
index.jsp: ......
<body>
<html:errors />
<h3><bean:message key="index.text1" /></h3>
<html:form action="/logon">
<bean:message key="index.prompt.username" />
<html:text property="username" /><br />
<bean:message key="index.prompt.password" />
<html:password property="password" /><br />
<bean:message key="index.prompt.group" />
<html:text property="group" /><br />
<html:submit>
<bean:message key="index.logon.submit" />
</html:submit>
</html:form>
</body> ......