struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Weber, Jeremy" <JWe...@Eventra.com>
Subject Out of my Mind/Struts Bug???
Date Fri, 24 Jan 2003 18:01:49 GMT
It seems to me that whenever I use requiredif and an additional custom
validation to validate the same field, the requiredif always passes and
therefore the second validation is called.  

Below I have cut some snippets from my code.  What I want to do is, require
properties B & C if property A is true.  Then after they are required I want
to do more validation.  Specifically I need to be able to call custom
validators such 'portRange'.  If I replace portRange in VALIDATION.XML
(below) with an included validation like integer or email, it works
perfectly.  Why the difference between the custom validation and the shipped
ones?  Perhaps I am not including something in my portRange definition or
code that is needed?  Or perhaps I am just out of my mind...:)

If someone smarted than me could check this out I would appreciate it....


TESTFORM.JSP
<table bgcolor=white border=0 width="45%">
<tr valign>
	<td><bean:message key="test.a.displayname"/></td>
	<td><html:text property="a" size=25 styleClass="input"/></td>
</tr>
<tr valign>
	<td><bean:message key="test.b.displayname"/></td>
	<td><html:text property="b" size=25 styleClass="input" /></td>
</tr>
<tr valign>
	<td class="mandatory"><bean:message key="test.c.displayname"/></td>
	<td><html:text property="c" size=25 styleClass="input"/></td>
</tr>
<tr><td colspan=2><html:submit/></td></tr>
</html:form>


VALIDATION.XML
			<field  property="a"
				depends="required">
				<arg0 key="test.a.displayname"/>
			<field  property="b"
				depends="requiredif,email">
				<arg0 key="test.b.displayname"/>
				<var>
					<var-name>field[0]</var-name>
					<var-value>a</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>true</var-value>
				</var>
			</field>
			<field  property="c"
				depends="requiredif,portRange">
				<arg0 key="test.c.displayname"/>
				<var>
					<var-name>field[0]</var-name>
					<var-value>a</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>true</var-value>
				</var>
			</field>




<validator name="portRange"
		 classname="com.vendorsite.install.util.validate.VsValidate"
		 method="validatePortRange"
		 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.portRange">
</validator>

And the actual code is this...

		public static boolean validatePortRange(java.lang.Object
bean,
		      org.apache.commons.validator.ValidatorAction va,
		      org.apache.commons.validator.Field field,
		      org.apache.struts.action.ActionErrors errors,
		      javax.servlet.http.HttpServletRequest request ) {

		      System.out.println("In PortRange
method--------------------------------");
		      String temp = ValidatorUtil.getValueAsString(bean,
field.getProperty());
		      String field1 = field.getProperty();
		      System.out.println("FIELD: " + field1);
		      System.out.println("VALUE: " + temp);
		      String sProperty2 =
field.getVarValue("secondProperty");
		      Map userData = (Map)
(request.getSession(false).getAttribute("userData"));
		      int number =
Integer.parseInt(userData.get(sProperty2).toString());
		      Integer test;
		      Enumeration enum;



		      System.out.println("NUM: " + number +
"--------------------------------");

		      Vector v = VectorUtil.convert(temp);
		      if (v == null){
	
errors.add(field.getKey(),StrutsValidatorUtil.getActionError(request,va,fiel
d));
			 System.out.println("First failure");
			 return false;
		      } else if (v.size() != number){
			 System.out.println(v.size());
			 System.out.println("Second failure");
	
errors.add(field.getKey(),StrutsValidatorUtil.getActionError(request,va,fiel
d));
			 return false;
		      } else {
			     //check to see if port nums make min max values
				  enum = v.elements ();
				  while (enum.hasMoreElements ()){
					test = (Integer)enum.nextElement();
					System.out.println("TEST: " + test);
					if (test.intValue() < 1 ||
test.intValue() > 65535){
						System.out.println("Third
failure");
						return false;
					}
				  }


		      }
		return true;
		}

Thanks

Jeremy Weber                        
jweber@eventra.com

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


Mime
View raw message