You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Cosmin Bucur <co...@gmail.com> on 2006/01/15 22:52:11 UTC
Re: adding a custom Type converter
So you need to configure a SqueezeAdaptor for each data object you are
using in tapestry ?
Also what's not clear to me is , does the tapestry end need to be
modified at all , or theese SqueezeAdaptors will simply work
automatically on the existing tap4 code .
Thanks
On 12/9/05, Paul Cantrell <ca...@pobox.com> wrote:
> I've done this, and it works quite well. You need to implement the
> interface org.apache.tapestry.util.io.SqueezeAdaptor, something like
> this:
>
> public class DomainObjectSqueezeAdaptor
> implements SqueezeAdaptor
> {
> public static final char PREFIX = '*';
> private static final Pattern squeezeFormat = Pattern.compile("\\*
> ([A-Za-z0-9_\\.\\$]+)_([0-9]+)");
>
> public String getPrefix()
> { return String.valueOf(PREFIX); }
>
> public Class getDataClass()
> { return DomainObject.class; }
>
> public String squeeze(DataSqueezer squeezer, Object data)
> { return squeeze(data); }
>
> public static String squeeze(Object data)
> {
> return PREFIX
> + data.getClass().getName()
> + '_'
> + ((DomainObject) data).getId();
> }
>
> public DomainObject unsqueeze(DataSqueezer squeezer, String s)
> { return unsqueeze(s); }
>
> public static DomainObject unsqueeze(String s)
> {
> Matcher matcher = squeezeFormat.matcher(s);
> if(!matcher.matches())
> throw new IllegalArgumentException("Unable to parse
> squeezed ID: " + s);
> String className = matcher.group(1);
> String id = matcher.group(2);
>
> Class type;
> try { type = Class.forName(className); }
> catch(ClassNotFoundException e)
> { throw new IllegalArgumentException("Unable to parse
> squeezed ID " + s, e); }
>
> return HibernateHelper.fromId((Class<? extends
> DomainObject>) type, id);
> }
> }
>
> Then add this to your hivemodule.xml:
>
> <contribution configuration-id="tapestry.data.SqueezeAdaptors">
> <adaptor
> object="instance:net.innig.core.web.tapestry.DomainObjectSqueezeAdaptor"
> />
> </contribution>
>
> Cheers,
>
> Paul
>
>
> On Dec 9, 2005, at 11:45 AM, Glen wrote:
>
> > I am converting a pre-existing webapp to use Tapestry 4.0. It uses
> > hibernate for the business objects and long's for the uid's on those
> > objects. I would like to use tapestry to coerce from the uid as a
> > string into the actual business object
> >
> > Ultimately what I want to be able to do is to write a direct link like
> > this...
> >
> >
> > <span jwcid="@DirectLink" listener="listener:gotoDetails"
> > parameters="ognl:bizObject">view details</span>
> >
> > public void gotoDetails( BizObject bizObject ) {
> > // rest of code goes here
> > }
> >
> > instead of how I am currently doing it as follows...
> >
> > <span jwcid="@DirectLink" listener="listener:gotoDetails"
> > parameters="ognl:bizobject.uid">view details</span>
> >
> > public void gotoDetails( Long uid ) {
> > BizObject bizObject = DAO.getBizObject( uid );
> > }
> >
> >
> > I know I need to use the tapestry.coerce.ValueConverter service. Can
> > anyone point me in the right direction as to how I would implement
> > this?
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
>
> _________________________________________________________________
> Piano music podcast: http://inthehands.com
> Other interesting stuff: http://innig.net
>
>
>
> ---------------------------------------------------------------------
> 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