You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Yura Tkachenko <tr...@gmail.com> on 2008/03/30 19:56:06 UTC

Does Tapestry have something like Converter in JSF?

Hi,

I have some experience in JSF and basically even now when I'm trying to
create some application in Tapestry sometimes I'm trying to find similar
solutions/approaches which I used in JSF. Anyway JSF provided such a good
thing like Converters. For example on your form you had text field to input
user id and in your POJO during handling submit event you need to load
hibernate object using userId parameter. Of course, one of the way to do it
is to create String property to userId and then in onSubmit try to load
using Hibernate User object by userId parameter. But in JSF I can create
Converter with two methods:

      getAsString(.....) // this method will convert User object to userId
string
      getAsObject(.....) // this method should convert userId parameter into
hibernate User entity

After that I need to register this converter and attach it to my text field
component. Also in my POJO I need to change property type from String to
User. This approach provides a lot of benefits and make possible to reuse it
on many pages where user can input 'userId' and we need to load Hibernate
entity User. This converter will be run automatically by JSF.

Does Tapestry 5 have something like converters?

Re: Does Tapestry have something like Converter in JSF?

Posted by Howard Lewis Ship <hl...@gmail.com>.
That's true, there's another interface, PrimaryKeyEncoder, that is also useful.

Generally, a ValueEncoder that fails will return null.  That null will
be picked up by the validators (say, the Required validator).  So
there is notification.

To me its two seperate use cases; the user will not be typing primary
keys in, those will be stored in hidden fields or elsewhere (i.e.
URLs).  They may not be valid (the underlying record may have been
deleted) ... or they may not be up-to date (there may have been a
conflicting update).  Both of those are cases to be handled by the
application, not by Tapestry, because no one solution is appropriate
to all applications.

On Sun, Mar 30, 2008 at 5:50 PM, Yura Tkachenko
<tr...@gmail.com> wrote:
> Well in JSF Convertors is a part of validation logic and they are provide a
>  way to notify application that conversion was unsuccessful. In Tapestry I
>  see Translator is almost the same as Converter in JSF. Using Translator I
>  can notify my application that conversion was unsuccessful. I've been
>  looking at
>  http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/ValueEncoder.htmland
>  I didn't find any way in ValueEncoder how I can throw any conversion
>  exception. Maybe someone can provide some more examples how ValueEncoder can
>  be used?
>
>
>
>  On Sun, Mar 30, 2008 at 2:08 PM, Howard Lewis Ship <hl...@gmail.com> wrote:
>
>  > Actually, this looks closer to the ValueEncoder interface.  For
>  > example, the tapestry-hibernate module includes ValueEncoders to
>  > convert between Hibernate entities and their primary keys (as
>  > strings).  The ValueEncoderSource interface is useful here, since it
>  > allows components that need a ValueEncoder to obtain one based on the
>  > type of property bound to their value parameter, automatically.
>  >
>  > On Sun, Mar 30, 2008 at 1:14 PM, Yura Tkachenko
>  > <tr...@gmail.com> wrote:
>  > > Thank you.
>  > >
>  > >
>  > >
>  > >  On 3/30/08, Thiago HP <th...@gmail.com> wrote:
>  > >  >
>  > >  > On 3/30/08, Yura Tkachenko <tr...@gmail.com> wrote:
>  > >  > >  Does Tapestry 5 have something like converters?
>  > >  >
>  > >  > Yes. Take a look at the Translator interfade
>  > >  > (
>  > >  >
>  > http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/Translator.html
>  > >  > )
>  > >  > and the translate parameter of the TextField component
>  > >  > (
>  > >  >
>  > http://tapestry.apache.org/tapestry5/tapestry-core/ref/org/apache/tapestry/corelib/components/TextField.html
>  > >  > )
>  > >  > and other related ones.
>  > >  >
>  > >  > --
>  > >  > Thiago
>  > >  >
>  > >  > ---------------------------------------------------------------------
>  > >  > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>  > >  > For additional commands, e-mail: users-help@tapestry.apache.org
>  > >  >
>  > >  >
>  > >
>  >
>  >
>  >
>  > --
>  > Howard M. Lewis Ship
>  >
>  > Creator Apache Tapestry and Apache HiveMind
>  >
>  > ---------------------------------------------------------------------
>  > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>  > For additional commands, e-mail: users-help@tapestry.apache.org
>  >
>  >
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

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


Re: Does Tapestry have something like Converter in JSF?

Posted by Yura Tkachenko <tr...@gmail.com>.
Well in JSF Convertors is a part of validation logic and they are provide a
way to notify application that conversion was unsuccessful. In Tapestry I
see Translator is almost the same as Converter in JSF. Using Translator I
can notify my application that conversion was unsuccessful. I've been
looking at
http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/ValueEncoder.htmland
I didn't find any way in ValueEncoder how I can throw any conversion
exception. Maybe someone can provide some more examples how ValueEncoder can
be used?

On Sun, Mar 30, 2008 at 2:08 PM, Howard Lewis Ship <hl...@gmail.com> wrote:

> Actually, this looks closer to the ValueEncoder interface.  For
> example, the tapestry-hibernate module includes ValueEncoders to
> convert between Hibernate entities and their primary keys (as
> strings).  The ValueEncoderSource interface is useful here, since it
> allows components that need a ValueEncoder to obtain one based on the
> type of property bound to their value parameter, automatically.
>
> On Sun, Mar 30, 2008 at 1:14 PM, Yura Tkachenko
> <tr...@gmail.com> wrote:
> > Thank you.
> >
> >
> >
> >  On 3/30/08, Thiago HP <th...@gmail.com> wrote:
> >  >
> >  > On 3/30/08, Yura Tkachenko <tr...@gmail.com> wrote:
> >  > >  Does Tapestry 5 have something like converters?
> >  >
> >  > Yes. Take a look at the Translator interfade
> >  > (
> >  >
> http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/Translator.html
> >  > )
> >  > and the translate parameter of the TextField component
> >  > (
> >  >
> http://tapestry.apache.org/tapestry5/tapestry-core/ref/org/apache/tapestry/corelib/components/TextField.html
> >  > )
> >  > and other related ones.
> >  >
> >  > --
> >  > Thiago
> >  >
> >  > ---------------------------------------------------------------------
> >  > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >  > For additional commands, e-mail: users-help@tapestry.apache.org
> >  >
> >  >
> >
>
>
>
> --
> Howard M. Lewis Ship
>
> Creator Apache Tapestry and Apache HiveMind
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Does Tapestry have something like Converter in JSF?

Posted by Howard Lewis Ship <hl...@gmail.com>.
Actually, this looks closer to the ValueEncoder interface.  For
example, the tapestry-hibernate module includes ValueEncoders to
convert between Hibernate entities and their primary keys (as
strings).  The ValueEncoderSource interface is useful here, since it
allows components that need a ValueEncoder to obtain one based on the
type of property bound to their value parameter, automatically.

On Sun, Mar 30, 2008 at 1:14 PM, Yura Tkachenko
<tr...@gmail.com> wrote:
> Thank you.
>
>
>
>  On 3/30/08, Thiago HP <th...@gmail.com> wrote:
>  >
>  > On 3/30/08, Yura Tkachenko <tr...@gmail.com> wrote:
>  > >  Does Tapestry 5 have something like converters?
>  >
>  > Yes. Take a look at the Translator interfade
>  > (
>  > http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/Translator.html
>  > )
>  > and the translate parameter of the TextField component
>  > (
>  > http://tapestry.apache.org/tapestry5/tapestry-core/ref/org/apache/tapestry/corelib/components/TextField.html
>  > )
>  > and other related ones.
>  >
>  > --
>  > Thiago
>  >
>  > ---------------------------------------------------------------------
>  > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>  > For additional commands, e-mail: users-help@tapestry.apache.org
>  >
>  >
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

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


Re: Does Tapestry have something like Converter in JSF?

Posted by Yura Tkachenko <tr...@gmail.com>.
Thank you.

On 3/30/08, Thiago HP <th...@gmail.com> wrote:
>
> On 3/30/08, Yura Tkachenko <tr...@gmail.com> wrote:
> >  Does Tapestry 5 have something like converters?
>
> Yes. Take a look at the Translator interfade
> (
> http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/Translator.html
> )
> and the translate parameter of the TextField component
> (
> http://tapestry.apache.org/tapestry5/tapestry-core/ref/org/apache/tapestry/corelib/components/TextField.html
> )
> and other related ones.
>
> --
> Thiago
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Does Tapestry have something like Converter in JSF?

Posted by Thiago HP <th...@gmail.com>.
On 3/30/08, Yura Tkachenko <tr...@gmail.com> wrote:
>  Does Tapestry 5 have something like converters?

Yes. Take a look at the Translator interfade
(http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/Translator.html)
and the translate parameter of the TextField component
(http://tapestry.apache.org/tapestry5/tapestry-core/ref/org/apache/tapestry/corelib/components/TextField.html)
and other related ones.

-- 
Thiago

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