Why has this been posted ans an answer to this thread? Please post a new thread (message not replying another). ;)

On Mon, 09 Apr 2012 14:05:12 -0300, Juan Alba <juan.a...@condortech.com.ar> wrote:

I am having some problems with this in 5.1.05

When I run the webapp I see how it gets to the environment.push but it
throws this runtime error:

Render queue error in AfterRender[ExceptionReport:layout]: No object
of type ar.com.condortech.lib.tapestryFbSecurityLib.extra.Mode is
available from the Environment.  Available types are
org.apache.tapestry5.RenderSupport,
org.apache.tapestry5.ValidationDecorator,
org.apache.tapestry5.internal.services.DocumentLinker,
org.apache.tapestry5.services.ClientBehaviorSupport,
org.apache.tapestry5.services.Heartbeat.


I don't know what I am doing wrong, as I said, it gets to the environment.push


any idea? Cheers!



On Wed, Apr 4, 2012 at 11:01 AM, Lance Java <lance.j...@googlemail.com>wrote:

Lets get back to basics here... you already have an instance of a link but
you want to transform a couple of methods to return slightly different
values. Let's forget about base path as it looks like that was added in 5.3
to make this job easier and we don't have that luxury in 5.1.05

In tapestry 5.1.05, it looks like you will need to transform the following
methods on the Link interface
   public String toURI();
   public String toRedirectURI();
   public String toAbsoluteURI();

I would do this in two phases, firstly I would create a DelegateLink class
which
  1. Contains no logic
  2. Implements Link
  3. Takes a Link instance in it's constructor (the delegate)
  4. Delegates all methods to the delegate

Then, add your specific logic in an anonymous inner class, this means that
DelegateLink can be re-used for other purposes.

private Link transform(final Link link) {
  ...
  transformed = new LinkDelegate(link) {
      public String toURI() {
          // do stuff with link.toURI();
      }
      public String toRedirectURI()  {
          // do stuff with link.toRedirectURI();
      }
      public String toAbsoluteURI() {
          // do stuff with link.toAbsoluteURI();
      }
  }
  ...
}

I already do this exact same trick to transform the request:

private Request transform(Request request) {
  ...
  transformed = new RequestDelegate(request) {
     public String getPath() {
        return newPath;
     }
  };
  ...
}

Tapestry plastic has some magic to create delegates for you but lets not go
there for simplicity ;)

On Wednesday, 4 April 2012, Juan Alba <juan.a...@condortech.com.ar> wrote:
> Sorry Lance but I don't understand how to replace the link with an
> interface if I can't make a copyWithBasePath because I cant set/access
all
> the attributes of the link.
>
> Sorry but I don't understand.
>
> I am talking about link.getBasePath() and
> the link.copyWithBasePath(newPath) in the method transform from the
> class ModeComponentEventLinkEncoder.
>
>
> Regards.
>
>
> On Tue, Apr 3, 2012 at 4:49 PM, Lance Java <lance.j...@googlemail.com
>wrote:
>
>> Take a look at my RequestDelegate class which delegates every method to
>> another class. I then override one method which I want to change.
>>
>> You could do exactly the same and create a LinkDelegate. After all, it's
>> just an interface
>>
>> :)
>>
>> On Tuesday, 3 April 2012, Juan Alba <juan.a...@condortech.com.ar>
wrote:
>> > First of all thanks a lot for all your time and help Lance. I have
used
>> > your example and worked perfect. I could use the mode to put the
>> > css dynamically as I wished. Thanks a lot.
>> >
>> > Now my problem is trying to use it in my web app. In tapestry 5.1.0.5
>> > LinkImpl doesn't have getBasePath(), or copyWithBasePath(). You are
using
>> > them in the ModeComponentEventLinkEncoder.
>> >
>> > I decided to replace the getBasePath() with toAbsoluteURI() and to
create
>> a
>> > private method to copy the link passing the link as an attribute but
it
>> is
>> > imposible to create an instance of LinkImpl from the link because I
can't
>> > get the values of optimizable, linkforForm, response, optimizer from
it.
>> > I don't know how to continue from here and if I can replace the
basePath
>> > with the AbsoluteUri. :(
>> >
>> > Thanks.
>> >
>> > On Sat, Mar 31, 2012 at 9:43 AM, Lance Java <
lance.j...@googlemail.com
>> >wrote:
>> >
>> >> I've put together a little demo decorating the
ComponentEventLinkEncoder
>> >> which I'm sure you could adapt to the deprecated URLRewriter if you
>> prefer
>> >> it that way. I've done it in tapestry 5.3 but it could be packported
to
>> >> tapestry 5.1.0.5 as is.
>> >>
>> >> I've setup three "special" prefixes for "foo", "bar" and "facebook"
>> >>
>> >> If you download it and mvn jetty:run then hit
>> >> http://localhost:8080/tapestry-sandbox/facebook/modepage1. You will
see
>> >> that the "mode" environmental is set to "facebook". Click on either
of
>> the
>> >> links and you will be sent to
>> >> http://localhost:8080/tapestry-sandbox/facebook/modepage2<
>> >> http://localhost:8080/tapestry-sandbox/facebook/modepage1>
>> >>
>> >> Likewise, you can try
>> >> http://localhost:8080/tapestry-sandbox/foo/modepage1<
>> >> http://localhost:8080/tapestry-sandbox/facebook/modepage1>
>> >> (mode
>> >> = foo)
>> >>
>> >> Or
>> >> http://localhost:8080/tapestry-sandbox/modepage1<
>> >> http://localhost:8080/tapestry-sandbox/facebook/modepage1>
>> >> (mode
>> >> = null)
>> >>
>> >>
>> >> Code is here
>> >> https://github.com/uklance/tapestry-sandbox
>> >>
>> >> Interesting files here
>> >>
>> >>
>>
>>

https://github.com/uklance/tapestry-sandbox/tree/master/src/main/java/com/github/uklance/extras
>> >>
>> >>
>> >> Cheers,
>> >> Lance.
>> >>
>> >
>>
>



--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
Consultor, desenvolvedor e instrutor em Java, Tapestry e Hibernate
http://www.arsmachina.com.br

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

Reply via email to