aspose file tools*
The moose likes Struts and the fly likes validator not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "validator not working" Watch "validator not working" New topic
Author

validator not working

Jeff Horan
Ranch Hand

Joined: Apr 03, 2003
Posts: 37
server log says i have an xml parse error, but i've tried even taking out the DOCTYPE line, like most examples show it and that didn't help. my config is: eclipse3.0.3,myeclipse4.0,winXPPro
#validation.xml
<!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="loginForm">
<field property="password" depends="required">
<arg0 key="login.password" />
</field>
<field property="username" depends="required">
<arg0 key="login.username" />
</field>
</form>
</formset>
</form-validation>

#struts config
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources />
<form-beans >
<form-bean name="loginForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="password" type="java.lang.String" />
<form-property name="userName" type="java.lang.String" />
</form-bean>
</form-beans>

<global-exceptions />
<global-forwards >
<forward name="welcome" path="/WEB-INF/login.jsp" />
</global-forwards>

<action-mappings >
<action
attribute="loginForm"
input="/WEB-INF/login.jsp"
name="loginForm"
path="/login"
scope="request"
type="com.jfh.struts.action.LoginAction" >
<forward name="survey" path="/WEB-INF/survey.jsp"/>
</action>
</action-mappings>

<message-resources parameter="com.jfh.struts.ApplicationResources" />

<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" property="pathnames"/>
</plug-in>

</struts-config>

#login.jsp
<%@ page language="java"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean"
prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html"
prefix="html"%>

<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css" />
<title><bean:message key="login.title" /></title>
</head>
<body>
<html:form action="/login">
<html:errors/><br/>
Password : <html:password property="password" />
<html:errors property="password" />
<br />
Username : <html:text property="userName" />
<html:errors property="userName" />
<br />

<html:submit />
<html:cancel />
</html:form>

</body>
</html>

#LoginAction.java
//Created by MyEclipse Struts
// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.4/xslt/JavaClass.xsl

package com.jfh.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.validator.DynaValidatorForm;

/**
* MyEclipse Struts
* Creation date: 02-18-2005
*
* XDoclet definition:
* @struts:action path="/login" name="loginForm" input="login.jsp" scope="request"
*/
public class LoginAction extends Action {

// --------------------------------------------------------- Instance Variables

// --------------------------------------------------------- Methods

/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{
DynaValidatorForm loginForm = (DynaValidatorForm) form;
return mapping.findForward("survey");

}

}

#ApplicationResources.properties
# Resources for parameter 'com.jfh.struts.ApplicationResources'
# Project ValidatorTest

# Struts Validator Error Messages
errors.required={0} is required.
errors.minlength={0} can not be less than {1} characters.
errors.maxlength={0} can not be greater than {1} characters.
errors.invalid={0} is invalid.

errors.byte={0} must be a byte.
errors.short={0} must be a short.
errors.integer={0} must be an integer.
errors.long={0} must be a long.
errors.float={0} must be a float.
errors.double={0} must be a double.

errors.date={0} is not a date.
errors.range={0} is not in the range {1} through {2}.
errors.creditcard={0} is an invalid credit card number.
errors.email={0} is an invalid e-mail address.
# END Struts Validator Error Messages

login.password=Password
login.username=User Name

#ERROR LOG
Jun 8, 2005 12:21:55 AM org.apache.commons.digester.Digester error
SEVERE: Parse Error at line 1 column 17: Document is invalid: no grammar found.
org.xml.sax.SAXParseException: Document is invalid: no grammar found.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.commons.digester.Digester.parse(Digester.java:1567)
at org.apache.commons.validator.ValidatorResources.<init>(ValidatorResources.java:159)
at org.apache.struts.validator.ValidatorPlugIn.initResources(ValidatorPlugIn.java:233)
at org.apache.struts.validator.ValidatorPlugIn.init(ValidatorPlugIn.java:164)
at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:839)
...


Jun 8, 2005 12:21:55 AM org.apache.commons.digester.Digester error
SEVERE: Parse Error at line 1 column 17: Document root element "form-validation", must match DOCTYPE root "null".
org.xml.sax.SAXParseException: Document root element "form-validation", must match DOCTYPE root "null".
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.commons.digester.Digester.parse(Digester.java:1567)
at org.apache.commons.validator.ValidatorResources.<init>(ValidatorResources.java:159)
at org.apache.struts.validator.ValidatorPlugIn.initResources(ValidatorPlugIn.java:233)
at org.apache.struts.validator.ValidatorPlugIn.init(ValidatorPlugIn.java:164)
at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:839)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:332)
...

well, you should have enough to reproduce it. it seems like a fairly simple example, but i'm pulling my hair out over this one. It will turn out to be something so simple.
Jeff Horan
Ranch Hand

Joined: Apr 03, 2003
Posts: 37
here are 2 other files you may need.
# welcome.jsp just outside WEB-INF
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic"
prefix="logic"%>
<html>
<logic:forward name="welcome" />
</html>

# survey.jsp just inside WEB-INF

<%@ page language="java"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean"
prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html"
prefix="html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic"
prefix="log"%>

<html:html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css" />
<title><bean:message key="Title" /></title>
</head>
<body>
<html:form action="/survey">
SURVEY
</html:form>
</body>
</html:html>

#####NOTE#####
login.jsp file is just inside WEB-INF


THANKS!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: validator not working