commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "struts commons" <commons1...@hotmail.com>
Subject new (custom) validation
Date Thu, 30 Sep 2004 13:49:18 GMT
Hello all,
I hope this question is not to remedial but I am really trying to understand 
what's wrong here.
I am trying to create a new validator for 'time'. I am basically parsing the 
string down to test components that make up the user input. I have followed 
numerous examples from books and internet to come up with the code below.
My new class seems to be the problem as I can get the client side to 
function and return a valid boolean but it will not give me the resource 
message either client side or server side. I am able to put alert message in 
my javascript and get those but it will not return with the .properties 
message I wrote. All other validation (date, required, etc.. etc..) works 
fine both client and server.
I included the code (minus the logic, I'm sure that is works) where I 
thought the problem may lie, but I'm new to Struts and fairly new to Java so 
if you need more I would be more than happy to oblige(just tell me what 
would help) but the rest of it seemed fairly standard and not where the 
problem may be.
Thanks in advance.
Jim

/************************************************************
new class I created

package com.gli.validator;

import java.io.Serializable;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.validator.Field;
import org.apache.commons.validator.ValidatorAction;
import org.apache.struts.action.ActionErrors;
import org.apache.commons.validator.GenericValidator;
import org.apache.commons.validator.ValidatorUtil;
import org.apache.struts.util.StrutsValidatorUtil;

public class GLIValidator implements Serializable {
  /**
   *
   **/
  public GLIValidator(){
  }

  public static boolean validateTime(Object bean, ValidatorAction va, Field 
field,
  ActionErrors errors, HttpServletRequest request) {

  //processing to validate (left out to shorten email but it works)
  // ValidatorUtil.getValueAsString(bean, field.getProperty() )
  //
  //

  return bValid;
  }

}

***************************************************************/

/**************************************************************
relevant portion of validator-rules.xml

       <validator name="time"
            classname="com.gli.validator.GLIValidator"
               method="validateTime"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionErrors,
                       javax.servlet.http.HttpServletRequest"
              depends="required"
                  msg="errors.time"
       jsFunctionName="TimeValidations">

         <javascript><![CDATA[
           function validateTime(form){

             // process to validate client side (left out to shorten email 
but it works)
                      return bValid;
           } ]]>
         </javascript>
      </validator>
/**************************************************************

/**************************************************************
relevant portion of validation.xml

  <form name="onCallLogForm">
       <field property="call_date" depends="required,date">
           <arg0 key="label.call_date"/>
               <var>
                   <var-name>datePatternStrict</var-name>
                   <var-value>MM/dd/yyyy</var-value>
               </var>
       </field>
       <field property="call_time" depends="required,time">
             <arg0 key="label.call_time"/>
       </field>
***************************************************************/

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! 
hthttp://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


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


Mime
View raw message