Struts Validator requiredif

Discussions

Web tier: servlets, JSP, Web frameworks: Struts Validator requiredif

  1. Struts Validator requiredif (6 messages)

    Did anyone try to use requiredif or validwhen in a webapp successfully?

    I try to use it, but it does not work.
    I read the spec, it wrote the requiredif is default in validator lib.
    Then I open the validation-rule.xml, I found that there is no javascript in requiredif tag, it is unlike required tag.

    Please tell me the solution if you can use requiredif in your project!
    Many Thanks.

    Threaded Messages (6)

  2. Struts Validator requiredif[ Go to top ]

    I have used it successfully. This is the validation.xml

    <form name="registrationForm">

        <field property="fromAddress"
                depends="required,email">
            <arg0 key="prompt.fromAddress"/>
        </field>

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

        <field property="replyToAddress"
                depends="email">
            <arg0 key="prompt.replyToAddress"/>
        </field>

        <field property="username"
                depends="required">
          <arg0 key="prompt.username"/>
        </field>
        <field property="password2"
                depends="required, requireif"
                 bundle="alternate">
          <arg0 key="prompt.password2"/>
          <arg1 key="error.password.match"/>
          <var>
            <var-name>test</var-name>
            <var-value>((password2 == password) and (*this* != null))</var-value>
          </var>
        </field>
    </form>

    This is the validation-rules-xml. You must make sure the class, org.apache.struts.validator.FieldChecks has the validateRequired method. This class is found in struts.jar.

    <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"/>

          <validator name="requiredif"
                     classname="org.apache.struts.validator.FieldChecks"
                     method="validateRequiredIf"
                     methodParams="java.lang.Object,
                                   org.apache.commons.validator.ValidatorAction,
                                   org.apache.commons.validator.Field,
                                   org.apache.struts.action.ActionMessages,
                                   org.apache.commons.validator.Validator,
                                   javax.servlet.http.HttpServletRequest"
                     msg="errors.required"/>
  3. Struts validation requiredif[ Go to top ]

    I am having a similar problem with requiredif. I checked struts.jar and I do have RequireIf() in it. Is it supposed to get a javaScript generated in validator-rules.xml and in the web page? If it doesn't is there something wrong with my jar file?

    Thanks.
  4. Struts validation requiredif[ Go to top ]

    I am having a similar problem with requiredif. I checked struts.jar and I do have RequireIf() in it. Is it supposed to get a javaScript generated in validator-rules.xml and in the web page? If it doesn't is there something wrong with my jar file?Thanks.


    requiredIf has been replaced with validWhen
  5. I am having a similar problem with requiredif. I checked struts.jar and I do have RequireIf() in it. Is it supposed to get a javaScript generated in validator-rules.xml and in the web page? If it doesn't is there something wrong with my jar file?Thanks.
    requiredIf has been replaced with validWhen

    It displayed error message from ActionError for me when validation fails.
  6. validwhen and requiredif do not work![ Go to top ]

    I have been try validwhen and requiredif but am unable to get my validation right. I have a boolean value based on which i decide if values in a dropdown are needed or not for the submit. can someone help me with this?
  7. Re: Struts validation requiredif[ Go to top ]

    I have tried your sample code too but it doesn seem to help me. Either it alerts incorreclty or doesn alert at all.