You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Wirama Putra <wi...@yahoo.com> on 2004/12/02 07:28:40 UTC

Formatter (and parser) for @TextField

Hi,

Sorry if this has been asked / discussed before, but I
couldn't find it in user guide / tapestry in action /
mailing list archive.

You see, I'm using JodaTime instead of JDK Date
package in my application. I want my Page to have:

- public abstract DateTime getIntervalStart()
- public abstract void setIntervalStart(DateTime
dateTime);

Now, I also want to have text field for inputting
intervalStart:

<input type="text" jwcid="@TextField"
value:"ognl:intervalStart"/>

I've tried running it on Tomcat and I got
ClassCastException (or NoMethodFound exception).
Because tapestry (or ognl?) passes String instead of
DateTime to invocation of setIntervalStart(...).

My question is: does Tapestry have a (simple)
mechanism for hooking our custom formatter+parser to
@TextField?

I'm thinking about something along this line:

<input type="text" jwcid="@TextField"
value:"ognl:intervalStart"
typeconverter="com.raka.JodaDateTimeConverter"/>

Converter's parse(...) will be called when Form is
submitted, before setting associated property on the
Page.

On the other side, Converter's format will be called
when rendering the page for display.

----

Best regards and Thanks in advance,
Raka (http://www.jroller.com/page/donraka)


	
		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - You care about security. So do we. 
http://promotions.yahoo.com/new_mail

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


Re: Formatter (and parser) for @TextField

Posted by Bryan Lewis <br...@maine.rr.com>.
Okay, that makes sense.  I didn't think of that as overhead because I
customized my Page class a long time ago to always have a
validationDelegate, and my TextField to have an optional validator and a
'required' attribute which obviates some of the need for a validator.

Still, I do occasionally have to declare a validator in the page spec.
Hmmm, lessee, if I customized Form to always use the page's delegate, that
would eliminate one more line from the spec. :-)   Naah... I'm content that
I don't have to cut-and-paste code for any of this!


----- Original Message ----- 
From: "Erik Hatcher" <er...@ehatchersolutions.com>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Thursday, December 02, 2004 8:27 AM
Subject: Re: Formatter (and parser) for @TextField


> On Dec 2, 2004, at 8:17 AM, Bryan Lewis wrote:
> > I'm confused.  Why isn't a ValidField good enough for this?  It's a
> > TextField with a customizable validator, which serves as a
> > formatter/parser.
> > Scales well enough with multiple components on the page.
>
> It's an "ok" solution, but requires a bit more overhead to use (a form
> delegate and validator).
>
> I want @ValidField to go away and for *every* form field component to
> be validate-able and convert-able.
>
> Erik
>
>
> >
> >
> > ----- Original Message -----
> > From: "Erik Hatcher" <er...@ehatchersolutions.com>
> > To: "Tapestry users" <ta...@jakarta.apache.org>
> > Sent: Thursday, December 02, 2004 5:45 AM
> > Subject: Re: Formatter (and parser) for @TextField
> >
> >
> >>
> >> On Dec 2, 2004, at 1:28 AM, Wirama Putra wrote:
> >>> You see, I'm using JodaTime instead of JDK Date
> >>> package in my application. I want my Page to have:
> >>>
> >>> - public abstract DateTime getIntervalStart()
> >>> - public abstract void setIntervalStart(DateTime
> >>> dateTime);
> >>>
> >>> Now, I also want to have text field for inputting
> >>> intervalStart:
> >>>
> >>> <input type="text" jwcid="@TextField"
> >>> value:"ognl:intervalStart"/>
> >>>
> >>> I've tried running it on Tomcat and I got
> >>> ClassCastException (or NoMethodFound exception).
> >>> Because tapestry (or ognl?) passes String instead of
> >>> DateTime to invocation of setIntervalStart(...).
> >>>
> >>> My question is: does Tapestry have a (simple)
> >>> mechanism for hooking our custom formatter+parser to
> >>> @TextField?
> >>
> >> Unfortunately not, sadly.  TextField binds to String, and thats it.
> >> You have two options, that I can think of:
> >>
> >>    * Handle the conversion yourself by binding a String to the
> >> TextField
> >> and validate/convert programatically in your listener method.  Con:
> >> this won't scale if you've got a lot of these fields on lots of pages.
> >>
> >>    * Create a CustomTextField component that does what you want.
> >>
> >> It's a shame TextField is so constraining.  Your example is exactly
> >> the
> >> reason why I've complained about TextField.  There is OGNL
> >> TypeConverter extensibility available in Tapestry that would work had
> >> TextField allowed bindings to Object.
> >>
> >>> I'm thinking about something along this line:
> >>>
> >>> <input type="text" jwcid="@TextField"
> >>> value:"ognl:intervalStart"
> >>> typeconverter="com.raka.JodaDateTimeConverter"/>
> >>>
> >>> Converter's parse(...) will be called when Form is
> >>> submitted, before setting associated property on the
> >>> Page.
> >>>
> >>> On the other side, Converter's format will be called
> >>> when rendering the page for display.
> >>
> >> A custom component wrapping TextField could do this with pretty
> >> minimal
> >> coding - just clone TextField and customize with a few lines of
> >> code/specification/template from there.
> >>
> >> Erik
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


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


Re: Formatter (and parser) for @TextField

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Dec 2, 2004, at 8:17 AM, Bryan Lewis wrote:
> I'm confused.  Why isn't a ValidField good enough for this?  It's a
> TextField with a customizable validator, which serves as a 
> formatter/parser.
> Scales well enough with multiple components on the page.

It's an "ok" solution, but requires a bit more overhead to use (a form 
delegate and validator).

I want @ValidField to go away and for *every* form field component to 
be validate-able and convert-able.

	Erik


>
>
> ----- Original Message -----
> From: "Erik Hatcher" <er...@ehatchersolutions.com>
> To: "Tapestry users" <ta...@jakarta.apache.org>
> Sent: Thursday, December 02, 2004 5:45 AM
> Subject: Re: Formatter (and parser) for @TextField
>
>
>>
>> On Dec 2, 2004, at 1:28 AM, Wirama Putra wrote:
>>> You see, I'm using JodaTime instead of JDK Date
>>> package in my application. I want my Page to have:
>>>
>>> - public abstract DateTime getIntervalStart()
>>> - public abstract void setIntervalStart(DateTime
>>> dateTime);
>>>
>>> Now, I also want to have text field for inputting
>>> intervalStart:
>>>
>>> <input type="text" jwcid="@TextField"
>>> value:"ognl:intervalStart"/>
>>>
>>> I've tried running it on Tomcat and I got
>>> ClassCastException (or NoMethodFound exception).
>>> Because tapestry (or ognl?) passes String instead of
>>> DateTime to invocation of setIntervalStart(...).
>>>
>>> My question is: does Tapestry have a (simple)
>>> mechanism for hooking our custom formatter+parser to
>>> @TextField?
>>
>> Unfortunately not, sadly.  TextField binds to String, and thats it.
>> You have two options, that I can think of:
>>
>>    * Handle the conversion yourself by binding a String to the 
>> TextField
>> and validate/convert programatically in your listener method.  Con:
>> this won't scale if you've got a lot of these fields on lots of pages.
>>
>>    * Create a CustomTextField component that does what you want.
>>
>> It's a shame TextField is so constraining.  Your example is exactly 
>> the
>> reason why I've complained about TextField.  There is OGNL
>> TypeConverter extensibility available in Tapestry that would work had
>> TextField allowed bindings to Object.
>>
>>> I'm thinking about something along this line:
>>>
>>> <input type="text" jwcid="@TextField"
>>> value:"ognl:intervalStart"
>>> typeconverter="com.raka.JodaDateTimeConverter"/>
>>>
>>> Converter's parse(...) will be called when Form is
>>> submitted, before setting associated property on the
>>> Page.
>>>
>>> On the other side, Converter's format will be called
>>> when rendering the page for display.
>>
>> A custom component wrapping TextField could do this with pretty 
>> minimal
>> coding - just clone TextField and customize with a few lines of
>> code/specification/template from there.
>>
>> Erik
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


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


Re: Formatter (and parser) for @TextField

Posted by Bryan Lewis <br...@maine.rr.com>.
I'm confused.  Why isn't a ValidField good enough for this?  It's a
TextField with a customizable validator, which serves as a formatter/parser.
Scales well enough with multiple components on the page.


----- Original Message ----- 
From: "Erik Hatcher" <er...@ehatchersolutions.com>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Thursday, December 02, 2004 5:45 AM
Subject: Re: Formatter (and parser) for @TextField


>
> On Dec 2, 2004, at 1:28 AM, Wirama Putra wrote:
> > You see, I'm using JodaTime instead of JDK Date
> > package in my application. I want my Page to have:
> >
> > - public abstract DateTime getIntervalStart()
> > - public abstract void setIntervalStart(DateTime
> > dateTime);
> >
> > Now, I also want to have text field for inputting
> > intervalStart:
> >
> > <input type="text" jwcid="@TextField"
> > value:"ognl:intervalStart"/>
> >
> > I've tried running it on Tomcat and I got
> > ClassCastException (or NoMethodFound exception).
> > Because tapestry (or ognl?) passes String instead of
> > DateTime to invocation of setIntervalStart(...).
> >
> > My question is: does Tapestry have a (simple)
> > mechanism for hooking our custom formatter+parser to
> > @TextField?
>
> Unfortunately not, sadly.  TextField binds to String, and thats it.
> You have two options, that I can think of:
>
>    * Handle the conversion yourself by binding a String to the TextField
> and validate/convert programatically in your listener method.  Con:
> this won't scale if you've got a lot of these fields on lots of pages.
>
>    * Create a CustomTextField component that does what you want.
>
> It's a shame TextField is so constraining.  Your example is exactly the
> reason why I've complained about TextField.  There is OGNL
> TypeConverter extensibility available in Tapestry that would work had
> TextField allowed bindings to Object.
>
> > I'm thinking about something along this line:
> >
> > <input type="text" jwcid="@TextField"
> > value:"ognl:intervalStart"
> > typeconverter="com.raka.JodaDateTimeConverter"/>
> >
> > Converter's parse(...) will be called when Form is
> > submitted, before setting associated property on the
> > Page.
> >
> > On the other side, Converter's format will be called
> > when rendering the page for display.
>
> A custom component wrapping TextField could do this with pretty minimal
> coding - just clone TextField and customize with a few lines of
> code/specification/template from there.
>
> Erik
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


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


Re: Formatter (and parser) for @TextField

Posted by Wirama Putra <wi...@yahoo.com>.
Thanks Eric,

Yep, I just did that (creating custom component,
cloning+modifying a bit from TextField). It works.
Thanks.

--- Erik Hatcher <er...@ehatchersolutions.com> wrote:

> 
> On Dec 2, 2004, at 1:28 AM, Wirama Putra wrote:
> > You see, I'm using JodaTime instead of JDK Date
> > package in my application. I want my Page to have:
> >
> > - public abstract DateTime getIntervalStart()
> > - public abstract void setIntervalStart(DateTime
> > dateTime);
> >
> > Now, I also want to have text field for inputting
> > intervalStart:
> >
> > <input type="text" jwcid="@TextField"
> > value:"ognl:intervalStart"/>
> >
> > I've tried running it on Tomcat and I got
> > ClassCastException (or NoMethodFound exception).
> > Because tapestry (or ognl?) passes String instead
> of
> > DateTime to invocation of setIntervalStart(...).
> >
> > My question is: does Tapestry have a (simple)
> > mechanism for hooking our custom formatter+parser
> to
> > @TextField?
> 
> Unfortunately not, sadly.  TextField binds to
> String, and thats it.  
> You have two options, that I can think of:
> 
>    * Handle the conversion yourself by binding a
> String to the TextField 
> and validate/convert programatically in your
> listener method.  Con: 
> this won't scale if you've got a lot of these fields
> on lots of pages.
> 
>    * Create a CustomTextField component that does
> what you want.
> 
> It's a shame TextField is so constraining.  Your
> example is exactly the 
> reason why I've complained about TextField.  There
> is OGNL 
> TypeConverter extensibility available in Tapestry
> that would work had 
> TextField allowed bindings to Object.
> 
> > I'm thinking about something along this line:
> >
> > <input type="text" jwcid="@TextField"
> > value:"ognl:intervalStart"
> > typeconverter="com.raka.JodaDateTimeConverter"/>
> >
> > Converter's parse(...) will be called when Form is
> > submitted, before setting associated property on
> the
> > Page.
> >
> > On the other side, Converter's format will be
> called
> > when rendering the page for display.
> 
> A custom component wrapping TextField could do this
> with pretty minimal 
> coding - just clone TextField and customize with a
> few lines of 
> code/specification/template from there.
> 
> 	Erik
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
> 
> 



		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Helps protect you from nasty viruses. 
http://promotions.yahoo.com/new_mail

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


Re: Formatter (and parser) for @TextField

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Dec 2, 2004, at 1:28 AM, Wirama Putra wrote:
> You see, I'm using JodaTime instead of JDK Date
> package in my application. I want my Page to have:
>
> - public abstract DateTime getIntervalStart()
> - public abstract void setIntervalStart(DateTime
> dateTime);
>
> Now, I also want to have text field for inputting
> intervalStart:
>
> <input type="text" jwcid="@TextField"
> value:"ognl:intervalStart"/>
>
> I've tried running it on Tomcat and I got
> ClassCastException (or NoMethodFound exception).
> Because tapestry (or ognl?) passes String instead of
> DateTime to invocation of setIntervalStart(...).
>
> My question is: does Tapestry have a (simple)
> mechanism for hooking our custom formatter+parser to
> @TextField?

Unfortunately not, sadly.  TextField binds to String, and thats it.  
You have two options, that I can think of:

   * Handle the conversion yourself by binding a String to the TextField 
and validate/convert programatically in your listener method.  Con: 
this won't scale if you've got a lot of these fields on lots of pages.

   * Create a CustomTextField component that does what you want.

It's a shame TextField is so constraining.  Your example is exactly the 
reason why I've complained about TextField.  There is OGNL 
TypeConverter extensibility available in Tapestry that would work had 
TextField allowed bindings to Object.

> I'm thinking about something along this line:
>
> <input type="text" jwcid="@TextField"
> value:"ognl:intervalStart"
> typeconverter="com.raka.JodaDateTimeConverter"/>
>
> Converter's parse(...) will be called when Form is
> submitted, before setting associated property on the
> Page.
>
> On the other side, Converter's format will be called
> when rendering the page for display.

A custom component wrapping TextField could do this with pretty minimal 
coding - just clone TextField and customize with a few lines of 
code/specification/template from there.

	Erik


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