You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by spm <ma...@tapestryforums.com> on 2006/01/16 17:35:11 UTC

NumericField for customer Number? etc

Seeing that Numeric Field is deprecated...what do people use for an entry field that can contain numerics only (such as customer number of length 10).

I tried a translator but its trying to convert to Long...which is not what I want.
Here is what I would like:


		
        
		
	


Like I said I tried the translator without success...should I write my own validator? Someone must have done something similar already...

Thanks!


-------------------- m2f --------------------

Sent from www.TapestryForums.com

Read this topic online here: <<topic_link>>

http://www.tapestryforums.com/viewtopic.php?p=13263#13263

-------------------- m2f --------------------



Re: NumericField for customer Number? etc

Posted by Kent Tong <ke...@cpttm.org.mo>.
Paul Ferraro <pmf8 <at> columbia.edu> writes:

> If you want to bind your field to a number with 10 digits, you should
> not need to write your own validator nor use custom logic in your listener.
> Try this:
> 
> <component id="customerNumber" type="TextField">
>     <binding name="value" value="customerNumber" />
>     <binding name="translator"
> value="translator:number,pattern=0000000000"/>
>     <binding name="validators"
> value="validators:required,min=0,max=9999999999"/>
>     <binding name="displayName" value="literal:Contract No."/>
> </component>

Well, if he'd like to treat say 123 as invalid because it
only contains 3 digits, not 10, then this won't work. Setting
the pattern to 0000000000 will only affect the formatting,
but not the parsing. 123 will still be accepted as valid.

--
Author of a book for learning Tapestry (www.agileskills2.org/EWDT)


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


Re: NumericField for customer Number? etc

Posted by Paul Ferraro <pm...@columbia.edu>.
If you want to bind your field to a number with 10 digits, you should
not need to write your own validator nor use custom logic in your listener.
Try this:

<component id="customerNumber" type="TextField">
    <binding name="value" value="customerNumber" />
    <binding name="translator"
value="translator:number,pattern=0000000000"/>
    <binding name="validators"
value="validators:required,min=0,max=9999999999"/>
    <binding name="displayName" value="literal:Contract No."/>
</component>

Paul

Kent Tong wrote:
> spm <maillist <at> tapestryforums.com> writes:
>
>   
>> Here is what I would like:
>>
>> <component id="customerNumber" type="TextField">
>> <binding name="value" value="customerNumber" />
>> <binding name="validators" 
>> value="validators:required,minLength=10,maxLength=10,numeric,omitZero=false"/>
>> <binding name="displayName" value="literal:Contract No."/>
>> </component> 
>>     
>
> If your customerNumber is a string, then you may try:
>
> <binding name="validators"
>   value="validators:required,pattern=\d{10}"/>
>
> If it is a number, then you'll need to write your own validator.
>
> --
> Author of a book for learning Tapestry (http://www.agileskills2.org/EWDT)
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>   


Re: NumericField for customer Number? etc

Posted by Kent Tong <ke...@cpttm.org.mo>.
spm <maillist <at> tapestryforums.com> writes:

> Here is what I would like:
>
> <component id="customerNumber" type="TextField">
> <binding name="value" value="customerNumber" />
> <binding name="validators" 
> value="validators:required,minLength=10,maxLength=10,numeric,omitZero=false"/>
> <binding name="displayName" value="literal:Contract No."/>
> </component> 

If your customerNumber is a string, then you may try:

<binding name="validators"
  value="validators:required,pattern=\d{10}"/>

If it is a number, then you'll need to write your own validator.

--
Author of a book for learning Tapestry (http://www.agileskills2.org/EWDT)


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


Re: NumericField for customer Number? etc

Posted by mike jones <mi...@gmail.com>.
It return a Number so try something like:

((Number) getTranslatedFieldSupport().parse(this, value)).intValue());



On 16/01/06, spm <ma...@tapestryforums.com> wrote:
>
> Seeing that Numeric Field is deprecated...what do people use for an entry
> field that can contain numerics only (such as customer number of length 10).
>
> I tried a translator but its trying to convert to Long...which is not what
> I want.
> Here is what I would like:
>
>
>
>
>
>
>
>
> Like I said I tried the translator without success...should I write my own
> validator? Someone must have done something similar already...
>
> Thanks!
>
>
> -------------------- m2f --------------------
>
> Sent from www.TapestryForums.com
>
> Read this topic online here: <<topic_link>>
>
> http://www.tapestryforums.com/viewtopic.php?p=13263#13263
>
> -------------------- m2f --------------------
>
>
>
>


--
d-_-b \m/(>_<)\m/ (9ò_ó)-o(@_o)

RE: NumericField for customer Number? etc

Posted by spm <ma...@tapestryforums.com>.
Kent Tong wrote:
> 
> Well, if he'd like to treat say 123 as invalid because it
> only contains 3 digits, not 10, then this won't work. Setting
> the pattern to 0000000000 will only affect the formatting,
> but not the parsing. 123 will still be accepted as valid.
> 


Thats correct, so time to write my own component then?

Thanks guys for the help! I'll give it shot.


-------------------- m2f --------------------

Sent from www.TapestryForums.com

Read this topic online here: <<topic_link>>

http://www.tapestryforums.com/viewtopic.php?p=13391#13391

-------------------- m2f --------------------



RE: NumericField for customer Number? etc

Posted by spm <ma...@tapestryforums.com>.
mike jones wrote:
> It return a Number so try something like:
> 
> ((Number) getTranslatedFieldSupport().parse(this, value)).intValue());
> 
> 
> 


Thanks!

I would have liked a numeric field which allowed zeros and validated on the client as well.


What I have gotten to work is:


     
     
     


And having in my page class:

public abstract String getCustomerNumber();

and perform the numeric validation and conversion on the submit...


I tried a translator with number, but if the user enters a number thats starts w zeros I was getting a ClassCastException in minLength (where it was trying to cast Long to String (even tho I had omitZero=false).


This will do for now...I may attempt to write my own NumericField, as I would really like the validation on the client. Should I start with the old NumericField? 

Before reinventing the wheel...does anyone have such a component?

Thanks!


-------------------- m2f --------------------

Sent from www.TapestryForums.com

Read this topic online here: <<topic_link>>

http://www.tapestryforums.com/viewtopic.php?p=13313#13313

-------------------- m2f --------------------