This worked wonderfully thanks...

One curiousity...  The "public static final char PREFIX = '*';"  Does
this have to be globally unique among all the SqueezeAdaptor's?  I am
assuming this must be unique to the squeeze adapter and that tapestry
will use this to differentiate what adaptor created the squeezed string
and hence what adaptor should unsqeeze the string.

Are there any guidelines about what prefixes are already taken?




Paul Cantrell 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: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
> 
> 
> _________________________________________________________________
> Piano music podcast: http://inthehands.com
> Other interesting stuff: http://innig.net
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to