Re: TextField hosting an Integer

2010-03-22 Thread Swanthe Lindgren

And add RangeValidator.

//Swanthe

On 2010-03-22 17:00, James Carman wrote:

Change your property to Integer and not int?  That way, it can be null
(which would show up as empty on the text field).

On Mon, Mar 22, 2010 at 11:09 AM, Steven Haines  wrote:
   

Hi,

I'm creating a text field to host an integer, namely the year that a house was 
built:
TextField  yearBuilt = new TextField( "yearBuilt" 
).setRequired( true );

And I'm using a CompoundPropertyModel that maps "yearBuilt" to an underlying bean property. My 
problem is that the default value for an integer is "0", so the text field pre-populates its value 
to "0", which is a rather silly year built date ;)  What I would like to do is mark the field as 
required and validate against a number range, but display the text field without an initial value.

I know I can make it a TextField  and then validate on submission, but what has me intrigued is my exploration 
into the DropDownChoice and the creation of renderers. For example, I have a dropdown list from which a user can choose a 
value between 0 and 50,000 (increments of 1000), but I built a custom renderer that displays "No Coverage" for 
"0" (insurance industry.) Can I build a custom renderer for the initial value of a text field so that if I see 
"0" I return "", otherwise I return the actual value, e.g. 2001?

Thanks in advance,
Steve


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org


 

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org


   




-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: TextField hosting an Integer

2010-03-22 Thread James Carman
Change your property to Integer and not int?  That way, it can be null
(which would show up as empty on the text field).

On Mon, Mar 22, 2010 at 11:09 AM, Steven Haines  wrote:
> Hi,
>
> I'm creating a text field to host an integer, namely the year that a house 
> was built:
> TextField yearBuilt = new TextField( "yearBuilt" 
> ).setRequired( true );
>
> And I'm using a CompoundPropertyModel that maps "yearBuilt" to an underlying 
> bean property. My problem is that the default value for an integer is "0", so 
> the text field pre-populates its value to "0", which is a rather silly year 
> built date ;)  What I would like to do is mark the field as required and 
> validate against a number range, but display the text field without an 
> initial value.
>
> I know I can make it a TextField and then validate on submission, but 
> what has me intrigued is my exploration into the DropDownChoice and the 
> creation of renderers. For example, I have a dropdown list from which a user 
> can choose a value between 0 and 50,000 (increments of 1000), but I built a 
> custom renderer that displays "No Coverage" for "0" (insurance industry.) Can 
> I build a custom renderer for the initial value of a text field so that if I 
> see "0" I return "", otherwise I return the actual value, e.g. 2001?
>
> Thanks in advance,
> Steve
>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: TextField hosting an Integer

2010-03-22 Thread Thierry Peng

Steven Haines schrieb:

Hi,

I'm creating a text field to host an integer, namely the year that a house was 
built:
TextField yearBuilt = new TextField( "yearBuilt" 
).setRequired( true );

And I'm using a CompoundPropertyModel that maps "yearBuilt" to an underlying bean property. My problem is that the default value for an integer is "0", so the text field pre-populates its value to "0", which is a rather silly year built date ;)  What I would like to do is mark the field as required and validate against a number range, but display the text field without an initial value. 


I know I can make it a TextField and then validate on submission, but what has me intrigued is my exploration 
into the DropDownChoice and the creation of renderers. For example, I have a dropdown list from which a user can choose a 
value between 0 and 50,000 (increments of 1000), but I built a custom renderer that displays "No Coverage" for 
"0" (insurance industry.) Can I build a custom renderer for the initial value of a text field so that if I see 
"0" I return "", otherwise I return the actual value, e.g. 2001?

Thanks in advance,
Steve


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

  

overwrite the getConverter on your textfield

@Override
   public IConverter getConverter(Class type)
   {
 NumberConverter fc = new NumberConverter()
 {
   @Override
   public String convertToString(Object value, Locale locale)
   {
   //insert your conversion logic here
   }
 };
 return fc;
   }

best

--
Thierry Peng


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org