You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Ilya Obshadko <il...@gmail.com> on 2013/11/05 20:11:17 UTC

Re: Tapestry5 Anchor Usage for Navigation

I've researched this problem a little bit and have an interesting question.

I would like to have a customized version of ActionLink (let's call it
HashActionLink). It should work as follows:

- if client-side JavaScript is enabled (and thus history events work), it
reacts to hash change events and updates specified zone
- if client-side JavaScript is disabled, it falls back to normal ActionLink
behavior

I suppose it might be handled using JS DOM manipulation in @AfterRender
phase.
Are there any other options to do that?



On Sun, Oct 27, 2013 at 4:24 PM, Ilya Obshadko <il...@gmail.com>wrote:

> Thanks for suggestions. I'm going to take a look at jquery-hashchange.
>
>
> On Sun, Oct 27, 2013 at 9:07 PM, Dmitry Gusev <dm...@gmail.com>wrote:
>
>> I wouldn't expect this functionality from Tapestry, because it can't and
>> shouldn't compete with client-side frameworks that should do this job.
>>
>> Tapestry 5.4 allows better pluggable client-site integration, so using
>> some
>> 3rd party client-side library for this stuff sounds reasonable. I'm sure
>> you've heard of this resource: http://todomvc.com and I'd try picking one
>> from there to integrate with tapestry.
>>
>> To start I'd recommend you to look at
>> http://benalman.com/projects/jquery-hashchange-plugin/ and maybe to
>> http://backbonejs.org/#Router as an example of handling hashchanged in
>> client-side MV* frameworks.
>>
>> I found jquery-hashchange-plugin very handy and it works very well for
>> simple cases where you simply want to trigger zone update from client-side
>> on hash changed (or initial page load).
>>
>>
>>
>> On Sun, Oct 27, 2013 at 12:41 PM, Ilya Obshadko <ilya.obshadko@gmail.com
>> >wrote:
>>
>> > That's understandable. However, *client-side* part of Tapestry might
>> deal
>> > with URL anchors in one way or another, for example, transforming them
>> to
>> > some kind of component events being sent to server over AJAX.
>> >
>> > This is actually what I'm interested in: to create some kind of 'bridge'
>> > between browser history events and Tapestry server-side events.
>> >
>> >
>> > On Sat, Oct 26, 2013 at 5:06 PM, Dmitry Gusev <dmitry.gusev@gmail.com
>> > >wrote:
>> >
>> > > Please note:
>> > >
>> > > Anchors or URL fragments as they are referred to in RFC
>> > > 1738<http://www.ietf.org/rfc/rfc1738.txt>,
>> > > > are not sent by the client to the server, when requesting for a
>> > resource.
>> > > >
>> > >
>> > >
>> > > So dealing with anchors is completely client-side job.
>> > >
>> > > Of course you can redirect from server-side to anchored URL.
>> > >
>> > >
>> > >
>> > > On Sat, Oct 26, 2013 at 6:54 AM, Ilya Obshadko <
>> ilya.obshadko@gmail.com
>> > > >wrote:
>> > >
>> > > > Found this thread while looking for a similar solution.
>> > > >
>> > > > - I'm using AJAX calls heavily and still want to be able to
>> represent
>> > > each
>> > > > page state as a separate URL.
>> > > > - I need to use anchor part of the URL in page activation handlers
>> > > >
>> > > > Is there any proper way to do that in 5.4?
>> > > >
>> > > >
>> > > >
>> > > > On Thu, Dec 1, 2011 at 8:04 AM, trsvax <tr...@gmail.com> wrote:
>> > > >
>> > > > > I was thinking about using that same library and gave up on the
>> whole
>> > > > idea
>> > > > > because of the emailing links problem and just went back to
>> reloading
>> > > the
>> > > > > whole page. The URL changes and the content changes. IMHO that is
>> the
>> > > > "more
>> > > > > native" approach. The history.js approach is full of difficult
>> > problems
>> > > > > such
>> > > > > as emailing a link to someone that does not run javascript.
>> Perhaps
>> > you
>> > > > > don't care about that edge case but I decided it was better to
>> > > > concentrate
>> > > > > on making the whole page load faster than solving all the AJAX
>> > history
>> > > > > problems. That said I do see the appeal and if everything
>> supported
>> > the
>> > > > > HTML
>> > > > > 5 way I might feel differently. I'm not knocking history.js and I
>> > think
>> > > > > #state is a cleaver hack but if the goal is to email links I think
>> > > > > reloading
>> > > > > the whole page is the only solution.
>> > > > >
>> > > > > --
>> > > > > View this message in context:
>> > > > >
>> > > >
>> > >
>> >
>> http://tapestry.1045711.n5.nabble.com/Tapestry5-Anchor-Usage-for-Navigation-tp5036547p5036735.html
>> > > > > Sent from the Tapestry - User mailing list archive at Nabble.com.
>> > > > >
>> > > > >
>> ---------------------------------------------------------------------
>> > > > > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> > > > > For additional commands, e-mail: users-help@tapestry.apache.org
>> > > > >
>> > > > >
>> > > >
>> > > >
>> > > > --
>> > > > Ilya Obshadko
>> > > >
>> > >
>> > >
>> > >
>> > > --
>> > > Dmitry Gusev
>> > >
>> > > AnjLab Team
>> > > http://anjlab.com
>> > >
>> >
>> >
>> >
>> > --
>> > Ilya Obshadko
>> >
>>
>>
>>
>> --
>> Dmitry Gusev
>>
>> AnjLab Team
>> http://anjlab.com
>>
>
>
>
> --
> Ilya Obshadko
>
>


-- 
Ilya Obshadko

Re: Tapestry5 Anchor Usage for Navigation

Posted by Ilya Obshadko <il...@gmail.com>.
So, I've ended up with this solution:

https://gist.github.com/xfyre/7369149

It kinda works. There are few things I don't like about it:

- it uses InternalComponentResources (which is, in fact, internal interface
not exposed as a public API)
- currently it supports only EventLink (though it may be easily extended to
use with ActionLink as well)
- if user loads an URL from browser history (or enters address into
location bar), we still have to load the page with it's default state and
THEN update relevant zone, which results in two consecutive requests

Any suggestions how to improve it are kindly appreciated.



On Wed, Nov 6, 2013 at 6:41 AM, Ilya Obshadko <il...@gmail.com>wrote:

> Yes, that looks much better than what I've originally proposed. Thanks.
>
>
> On Tue, Nov 5, 2013 at 11:22 PM, Thiago H de Paula Figueiredo <
> thiagohp@gmail.com> wrote:
>
>> On Tue, 05 Nov 2013 17:11:17 -0200, Ilya Obshadko <
>> ilya.obshadko@gmail.com> wrote:
>>
>>  I've researched this problem a little bit and have an interesting
>>> question.
>>>
>>> I would like to have a customized version of ActionLink (let's call it
>>> HashActionLink). It should work as follows:
>>>
>>> - if client-side JavaScript is enabled (and thus history events work), it
>>> reacts to hash change events and updates specified zone
>>> - if client-side JavaScript is disabled, it falls back to normal
>>> ActionLink
>>> behavior
>>>
>>> I suppose it might be handled using JS DOM manipulation in @AfterRender
>>> phase.
>>> Are there any other options to do that?
>>>
>>
>> You can do this with an ordinary ActionLink or EventLink and do the logic
>> you describe in JavaScript, listening to clicks to the link and stopping
>> its propagation so the browser doesn't do the normal link behavior. For
>> monitoring hash changes, you can try some JavaScript library that can do
>> that.
>>
>> --
>> Thiago H. de Paula Figueiredo
>> Tapestry, Java and Hibernate consultant and developer
>> http://machina.com.br
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
> --
> Ilya Obshadko
>
>


-- 
Ilya Obshadko

Re: Tapestry5 Anchor Usage for Navigation

Posted by Ilya Obshadko <il...@gmail.com>.
Yes, that looks much better than what I've originally proposed. Thanks.


On Tue, Nov 5, 2013 at 11:22 PM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Tue, 05 Nov 2013 17:11:17 -0200, Ilya Obshadko <il...@gmail.com>
> wrote:
>
>  I've researched this problem a little bit and have an interesting
>> question.
>>
>> I would like to have a customized version of ActionLink (let's call it
>> HashActionLink). It should work as follows:
>>
>> - if client-side JavaScript is enabled (and thus history events work), it
>> reacts to hash change events and updates specified zone
>> - if client-side JavaScript is disabled, it falls back to normal
>> ActionLink
>> behavior
>>
>> I suppose it might be handled using JS DOM manipulation in @AfterRender
>> phase.
>> Are there any other options to do that?
>>
>
> You can do this with an ordinary ActionLink or EventLink and do the logic
> you describe in JavaScript, listening to clicks to the link and stopping
> its propagation so the browser doesn't do the normal link behavior. For
> monitoring hash changes, you can try some JavaScript library that can do
> that.
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Ilya Obshadko

Re: Tapestry5 Anchor Usage for Navigation

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 05 Nov 2013 17:11:17 -0200, Ilya Obshadko  
<il...@gmail.com> wrote:

> I've researched this problem a little bit and have an interesting  
> question.
>
> I would like to have a customized version of ActionLink (let's call it
> HashActionLink). It should work as follows:
>
> - if client-side JavaScript is enabled (and thus history events work), it
> reacts to hash change events and updates specified zone
> - if client-side JavaScript is disabled, it falls back to normal  
> ActionLink
> behavior
>
> I suppose it might be handled using JS DOM manipulation in @AfterRender
> phase.
> Are there any other options to do that?

You can do this with an ordinary ActionLink or EventLink and do the logic  
you describe in JavaScript, listening to clicks to the link and stopping  
its propagation so the browser doesn't do the normal link behavior. For  
monitoring hash changes, you can try some JavaScript library that can do  
that.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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