There is a short article in the wiki that shows how to
create your own 
validator.
http://wiki.apache.org/jakarta-tapestry/HowTos

You need something like the following.

public class IntegerValidator extends BaseValidator {

        public void validate(IFormComponent form, 
                        ValidationMessages messages, Object obj)
                     throws ValidatorException {
                String input = (String)obj;
                try {
                        Integer.parseInt(input.trim());
                }
            catch (NumberFormatException nfe){
                throw new ValidatorException(getMessage());
            }
                
        }

}

Add the following to  hivemodule.xml :

  <contribution
configuration-id="tapestry.form.validator.Validators">
       <validator name="integer" configurable="true"            
                       
class="math.validators.IntegerValidator"/>
   </contribution>


In your .page :
 <bean name="integerValidator" 
               
class="math.validators.IntegerValidator">
        <set name="message" value="literal:Preference
must be an integer"/>        
    </bean>

  <binding name="validators"
value="validators:$integerValidator"/>




Shing

--- Jun Tsai <[EMAIL PROTECTED]> wrote:

> hi
>   I didn't find a int validator defied in
> tapestry.form.validator.Validators.I want to
> 
>  <component type="TextField"
> id="molecularWeightField">
>     <binding name="displayName"
> value="message:molecularWeight"/>
>     <binding name="translator"
> value="translator:number"/>
>     <binding name="validators"
> value="validators:int,maxLength=10"/>
>     <binding name="value"
> value="ognl:entity.molecularWeight"/>
>   </component>
> 
> but no int validator.
> 
> How to do ?
> 
> Thanks
> 
> Jun Tsai
> --
> Welcome to China Java Users Group(CNJUG).
> http://cnjug.dev.java.net
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 
> 


Home page :
  http://uk.geocities.com/matmsh/index.html


        
        
                
___________________________________________________________ 
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail 
http://uk.messenger.yahoo.com

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

Reply via email to