You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Udaya Allu <ua...@register.com> on 2003/08/17 16:08:22 UTC

requiredif - Is this correct or wrong ? -Help me

Hello Dear All,
Please help me to find fault in hte following code 
for requiredif validation and identical(password) comparision
that worked fine in Struts 1.1 RC1 but giving
java.lang.NullPointerException with Struts 1.1 final release
at org.apache.struts.validator.FieldChecks.validateRequiredIf(FieldChecks.java:200)
Please help me.
Thanks -Udaya


<form name="myaccountEmailForm">
		<field property="newpassword" depends="requiredif,identical">
		<arg0 key="form.password.new"/>
		<arg1 key="form.password.confirm"/>
		  <var>
		    <var-name>field[0]</var-name>
		    <var-value>currentPage</var-value>
		  </var>
		  <var>
		    <var-name>field-test[0]</var-name>
		    <var-value>EQUAL</var-value>
		  </var>		  
		  <var>
		    <var-name>field-value[0]</var-name>
		    <var-value>2</var-value>
		  </var>
			<var>
			<var-name>secondProperty</var-name>
			<var-value>confirmpassword</var-value>
		  </var>
		</field>
	</form>

	 
<validator name="identical"
		classname="com.register.utils.ValidateUtil"
		method="validateIdentical"
		methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionErrors,
                       javax.servlet.http.HttpServletRequest"		
		depends="requiredif"
		msg="errors.identical"/>
<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.ActionErrors,
                               org.apache.commons.validator.Validator,
                                javax.servlet.http.HttpServletRequest"
                  msg="errors.required">
   </validator>
public static boolean validateIdentical(Object bean, ValidatorAction va,
        Field field, ActionErrors errors, HttpServletRequest request) {
        String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
        String sProperty2 = field.getVarValue("secondProperty");
        String value2 = ValidatorUtil.getValueAsString(bean, sProperty2);

        if (!GenericValidator.isBlankOrNull(value)) {
            try {
                if (!value.equals(value2)) {
                    errors.add(field.getKey(),
                        Resources.getActionError(request, va, field));

                    return false;
                }
            } catch (Exception e) {
                errors.add(field.getKey(),
                    Resources.getActionError(request, va, field));

                return false;
            }
        }

        return true;
    }

Caused by: java.lang.NullPointerException
	at org.apache.struts.validator.FieldChecks.validateRequiredIf(FieldChecks.java:200)
	... 43 more
12:01:23,995 ERROR [Validator] reflection: null
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:324)
	at org.apache.commons.validator.Validator.validateFieldForRule(Validator.java:435)
	at org.apache.commons.validator.Validator.validateField(Validator.java:512)

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org