struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kote, Nijaguna Sangankal" <nijaguna-sangankal.k...@hp.com>
Subject Javascript error in struts validator.
Date Fri, 02 Jul 2004 06:37:46 GMT
Hi All,
	I had posted this question, but got now answer. Please give me
some hints on this.

	I am getting javascript error when I click on submit to validate
my form.
	It's a simple login page with username and password.

	here is the code for login.jsp

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

<%
    response.setHeader("pragma", "no-cache");
    response.setHeader("Cache-control", "no-cache, no-store");
    response.setHeader("Expires", "0");
%>

<html:html locale="true">

<head>
	<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
	<link href="../css/asianet.css" type=text/css rel=stylesheet>
	<title><bean:message key="title.login"/></title>
	<html:javascript formName="loginForm"/> - This is how I am
including the Javascript for validation.
</head>
........................................... Rest body code goes here.
</html:html>

This is my validation.xml file
<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE form-validation PUBLIC
          "-//Apache Software Foundation//DTD Commons Validator Rules
Configuration 1.1//EN"
          "http://jakarta.apache.org/commons/dtds/validator_1_1.dtd">

<form-validation>

    <formset>

        <form    name="loginForm">
            <field     property="j_username"
                        depends="required">
                <arg0 key="prompt.userid"/>
            </field>

            <field     property="j_password"
                        depends="required">
                   <arg0 key="prompt.password"/>
            </field>

        </form>
    </formset>

</form-validation>

And validation-rules.xml file
<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.ActionErrors,
                       javax.servlet.http.HttpServletRequest"
                  msg="errors.required">

         <javascript><![CDATA[
            function validateRequired(form) {
                var isValid = true;
                var focusField = null;
                var i = 0;
                var fields = new Array();
                oRequired = new required();  //-> here is the error.
                for (x in oRequired) {
                	var field = form[oRequired[x][0]];
                	
                    if (field.type == 'text' ||
                        field.type == 'textarea' ||
                        field.type == 'file' ||
                        field.type == 'select-one' ||
                        field.type == 'radio' ||
                        field.type == 'password') {
                        .............................. Rest

Now when I load my jsp, struts generates javascript with
validateLoginForm( document.loginForm )mehtod.
But, when I click on submit button. I get javascript error saying
"required is undefined" and it points to the above bold line in 
Validation-rules.xml file.

I am not able to figure out why, any ideas or hints on this would help
me a lot.

Thanks
Guna

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message