You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by bhorvat <ho...@gmail.com> on 2013/03/04 23:24:30 UTC

Best generic way to use zones

Hi all,

I have a question about what should be the best approach to use zone in
somewhat generic way. 

Basically I have something like this 


private void refreshAjaxZones(Zone... zone) {
        for (Zone tempZone : zone) {
            ajaxResponseRenderer.addRender(tempZone);
        }
        injectJavascriptCall();
}

Now in my event methods I call this and submit a list of zones that needs to
be refreshed. 

@Inject
private Zone myZone

...

refreshAjaxZones(myZone);

In order for this to work my zones need to be defined 

<t:zone t:id="myZone" id="myZone" >some html</zone>

In my real world example I have more then one zone. So based on that I have
made the following observations 

If I dont set html id (ie not t:id but actually id) then this fails. What
happens is that one of the zone gets updated with the wrong content data. So
I guess that having this html id is really important but what I dont get it
why cant a zone figure out the id?

This generates the same broken zone effect

            ajaxResponseRenderer.addRender(tempZone.getClientId, tempZone);

I would expect that this is called inside
ajaxResponseRenderer.addRender(tempZone);

However this if I call zone by submitting a string as a name it works 

            ajaxResponseRenderer.addRender("myZone", myZone);

In this case I dont have to have html id for the zone. 

So my question is why does this id needs to be set manually and is it ok to
set it and then refresh the zone the way I do? 

If I want to move this behaviour to some utility class would static method
be ok for this(assuming I pass render into the argument list). Or should I
create is as service and use @Inject as I presume that in this case I could
also @Inject render inside the service...

Cheers and thanks for the explanations :D

PS. Dont pay any attention to injectJavascriptCall() as this just injects
some javascript that needs to be triggered on the client end. 




--
View this message in context: http://tapestry.1045711.n5.nabble.com/Best-generic-way-to-use-zones-tp5720333.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


Re: Best generic way to use zones

Posted by bhorvat <ho...@gmail.com>.
Ok that explains a bit better. Then I will proceed with my code.

Thanks sody you have been very helpfully

All the best
Cheers



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Best-generic-way-to-use-zones-tp5720333p5720362.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


Re: Best generic way to use zones

Posted by Ivan Khalopik <ik...@gmail.com>.
Tapestry generates ids for components using id allocation mechanism. E.g.

<t:zone t:id="myZone">...</t:zone>

In this case T5 will try to allocate "myZone" as id for zone. If this id is
already allocated by some other component it will try "myZone_0", then
"myZone_1"...
This rule is broken inside ajax requests as page is populated partially and
T5 doesn't know anything about existent component ids. In this case some
random unique namespace will be added to all generated component ids. E.g.
"myZone_13d3991d3a9", then "myZone_13d3991d3a9_0", "myZone_13d3991d3a9_1"...

Lets see what happens in your example. When you render your zone you will
have zone id "myZone". Then you do ajax request to server and refresh this
zone, and its id become "myZone_13d3991d3a9". Then browser gets back ajax
response and can't find such zone("myZone_13d3991d3a9") and you have error.

As a workaround Zone component has id parameter.

<t:zone t:id="myZone" id="myZone">...</t:zone>

If this parameter is bound Zone will ignore id allocation mechanism and
will use this id instead. So I follow the rule to always use id parameter
for Zone components. But if you use this parameter be sure that it is
unique within the page. Also be careful when using it inside loop as it can
result in the same id for all zones.

On Tue, Mar 5, 2013 at 1:24 AM, bhorvat <ho...@gmail.com> wrote:

> Hi all,
>
> I have a question about what should be the best approach to use zone in
> somewhat generic way.
>
> Basically I have something like this
>
>
> private void refreshAjaxZones(Zone... zone) {
>         for (Zone tempZone : zone) {
>             ajaxResponseRenderer.addRender(tempZone);
>         }
>         injectJavascriptCall();
> }
>
> Now in my event methods I call this and submit a list of zones that needs
> to
> be refreshed.
>
> @Inject
> private Zone myZone
>
> ...
>
> refreshAjaxZones(myZone);
>
> In order for this to work my zones need to be defined
>
> <t:zone t:id="myZone" id="myZone" >some html</zone>
>
> In my real world example I have more then one zone. So based on that I have
> made the following observations
>
> If I dont set html id (ie not t:id but actually id) then this fails. What
> happens is that one of the zone gets updated with the wrong content data.
> So
> I guess that having this html id is really important but what I dont get it
> why cant a zone figure out the id?
>
> This generates the same broken zone effect
>
>             ajaxResponseRenderer.addRender(tempZone.getClientId, tempZone);
>
> I would expect that this is called inside
> ajaxResponseRenderer.addRender(tempZone);
>
> However this if I call zone by submitting a string as a name it works
>
>             ajaxResponseRenderer.addRender("myZone", myZone);
>
> In this case I dont have to have html id for the zone.
>
> So my question is why does this id needs to be set manually and is it ok to
> set it and then refresh the zone the way I do?
>
> If I want to move this behaviour to some utility class would static method
> be ok for this(assuming I pass render into the argument list). Or should I
> create is as service and use @Inject as I presume that in this case I could
> also @Inject render inside the service...
>
> Cheers and thanks for the explanations :D
>
> PS. Dont pay any attention to injectJavascriptCall() as this just injects
> some javascript that needs to be triggered on the client end.
>
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Best-generic-way-to-use-zones-tp5720333.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
>
>


-- 
BR
Ivan