[EMAIL PROTECTED] wrote:

Hi Vinicius,
        
        An easy question, have you put the right attribute in the
struts-config.xml in the actionMapping ?
You need to put the xml attribute validate="true" and an input for the page
you want to return if the validation throw an error. An exemple :

                        <action path="/createMPFromCollection"
                        type="plateinv.actions.plate.MPCreateAction"
                        name="mpCollectionForm"
                        parameter="method"
                        validate="true"
                        input="tiles.plate.master.create.option">
                                <forward name="createMP"
path="tiles.plate.master.create.confirmationMP"/>
                        </action>

                           Charles

-----Original Message-----
From: Vinicius Carvalho [mailto:[EMAIL PROTECTED]
Sent: September 30, 2004 1:43 PM
To: [EMAIL PROTECTED]
Subject: Validator


Hi there! I've been using Struts for quite sometime, but haven't used the validator yet.
So I followed the receipt provided by Struts in Action, but got no success at all.


Here's what I've done

Struts-config is configured for the right plugin
My ActionForm extends ValidatorForm and has no validate() method

Validator-rules.xml:

   <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="validator.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>


validation.xml:

<form name="userForm">
<field property="nome" depends="required">
<msg name="obrigatorio" key="validator.errors.required"/>
<arg0 key="prompt.nome"/>
</field> </form> ApplicationResources.properties


validator.errors.required= O campo {0} é obrigatório
prompt.nome=nome


And my jsp file looks like this:

<html:form action="/atualizaDadosUsuarioAction" name="userForm" type="br.com.auge.errors.action.form.UserForm" onsubmit="return validateRequired(this)">
Nome <html:text property="nome" name="userForm"></html:text><html:errors /><br>
</html:form>
<html:javascript formName="userForm"/>



Well, what is happening is that after I submit with no values at all, nothing happens, it forwards to the
correct path. And also, the javascript generated isn't inside a <script></script> block. So it's printed
on the page footer.


Where did I miss?

Thanks

Vinicius

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



------------------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Yep, both attributes are set. Any ideas?

Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to