Avatar of Econify
Econify
 asked on

Getting error while using Validation in Struts Application..

Hi all,

I am getting a very strange, intermittent error. While
modifying or adding forms and actions, my app will be
running fine. But when I am trying to use Client-side validation into my application, I am getting following error:-
==================================================================
"org.apache.jasper.JasperException: Depends string "required" was not found in validator-rules.xml."
==================================================================

Follwin are entries in Struts config.xml file:-
==============================================
      <message-resources parameter="com.econify.struts.ApplicationResources" />
      <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
            <set-property property="pathnames"
                  value="/org/apache/struts/validator/validator-rules.xml,
    /WEB-INF/validation.xml" />
      </plug-in>
================================================
My content of validation.xml file is:-
==============================
<form-validation>
  <formset>
    <form name="userForm">
      <field property="username"
            depends="required">
        <arg0 key="userRegistration.username.null"/>
      </field>
    </form>
  </formset>
</form-validation>
==============================
& validator-rules.xml file is:-
===================================
    <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();
                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') {
                       
                        var value = '';
                                    // get field's value
                                    if (field.type == "select-one") {
                                          var si = field.selectedIndex;
                                          if (si >= 0) {
                                                value = field.options[si].value;
                                          }
                                    } else {
                                          value = field.value;
                                    }
                       
                        if (trim(value).length == 0) {
                       
                              if (i == 0) {
                                  focusField = field;
                              }
                              fields[i++] = oRequired[x][1];
                              isValid = false;
                        }
                    }
                }
                if (fields.length > 0) {
                   focusField.focus();
                   alert(fields.join('\n'));
                }
                return isValid;
            }
           
            // Trim whitespace from left and right sides of s.
            function trim(s) {
                return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
            }
           
            ]]>
         </javascript>

      </validator>
====================================
& in one of my jsp file I am using "userForm" formbean in which I am writing following for using Claient side validation.
====================================
<html:javascript formName="userForm"/>
====================================
Why I am getting this error? PLease help me.
Thank you.
Pras

JSP

Avatar of undefined
Last Comment
jaggernat

8/22/2022 - Mon
mbvvsatish

> <validator name="required"

in your validator-rules.xml try changing name="required to

depends="required"
mbvvsatish

sorry ignore my previous post. i think the issue is a different one
ASKER CERTIFIED SOLUTION
jaggernat

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
jaggernat

could you resolve the problem?
J

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy