You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by JumpStart <ge...@gmail.com> on 2023/01/03 14:47:16 UTC

Updating specific zone instances in a loop.

Hi all,

Let’s say I have loop around a zone, and on a particular event I want to render just the 2nd and 4th instances of the zone. How do I do that?

	<t:loop source="1..10" value="zoneIndex">
			
		<t:zone t:id=“thingZone" id="prop:zoneId” >
			<!— Contents from thing goes here. —>
		</t:zone>
				
	</t:loop>

	@Property
	private int zoneIndex;

	@InjectComponent
	private Zone thingZone;

	public String getZoneId() {
		return “thingZone_" + zoneIndex;
	}

My problem is that the following does not correctly render thing 2 and 4.

	public String onMyEvent() {

		thing = getThing(2);
		zoneIndex = 2;
		ajaxResponseRenderer.addRender(thingZone);

		thing = getThing(4);
		zoneIndex = 4;
		ajaxResponseRenderer.addRender(thingZone);

		thing = null;

	}

As you can see below, the response includes the right zone names, but the rendered content of them is the same and is based on whatever the final values were. In this case the final value of thing was null, so white space was rendered into both zones.

{
  "_tapestry" : {
    "content" : [
      [
        “thingZone_4",
        "\n\t\t\t\t\t\t\t\t\n\t\t\t\t"
      ],
      [
        “thingZone_2",
        "\n\t\t\t\t\t\t\t\t\n\t\t\t\t"
      ]
    ],
    "inits" : [

So addRender(ClientBodyElementZone zone) queues up the request for later. Can I somehow queue up each request with the current values that I want it to use when rendering?

Cheers,

Geoff

Re: Updating specific zone instances in a loop.

Posted by JumpStart <ge...@gmail.com>.
Thank you Dmitry, that is exactly what I needed. Absolutely marvellous. I will try to put an example in JumpStart as soon as I can, because as far as I can tell there is no other documented example around of how to solve this problem or how to use RenderCommand used in this way.

Cheers,
Geoff

> On 4 Jan 2023, at 1:53 am, Dmitry Gusev <dm...@gmail.com> wrote:
> 
> Hi Geoff,
> 
> You can pass an instance of the RenderCommand that could capture the
> context, hopefully this snippet can give a hint.
> 
> Regards,
> Dmitry
> 
> for (int i = 0; i < emailIds.length; i++)
> {
>    String emailId = emailIds[i];
>    boolean display = displayStatusArray[i];
> 
>    // Set tempId for getEmailStatusZoneId()
>    tempId = emailId;
> 
>    // There may be multiple instances of this component being
> refreshed at the same time,
>    // so we need to render it immediately
>    ajaxResponseRenderer.addRender(getEmailStatusZoneId(),
> (RenderCommand) (writer, queue) -> {
>        // Initialise before rendering
>        EmailDeliveryStatus.this.tempId = emailId;
>        EmailDeliveryStatus.this.show = display;
>        setupEmail();
> 
>        ((RenderCommand) emailStatusZone.getBody()).render(writer, queue);
> 
>        initJavaScript();
>    });
> }
> 
> 
> 
> On Tue, Jan 3, 2023 at 2:47 PM JumpStart <
> geoff.callender.jumpstart@gmail.com> wrote:
> 
>> Hi all,
>> 
>> Let’s say I have loop around a zone, and on a particular event I want to
>> render just the 2nd and 4th instances of the zone. How do I do that?
>> 
>>        <t:loop source="1..10" value="zoneIndex">
>> 
>>                <t:zone t:id=“thingZone" id="prop:zoneId” >
>>                        <!— Contents from thing goes here. —>
>>                </t:zone>
>> 
>>        </t:loop>
>> 
>>        @Property
>>        private int zoneIndex;
>> 
>>        @InjectComponent
>>        private Zone thingZone;
>> 
>>        public String getZoneId() {
>>                return “thingZone_" + zoneIndex;
>>        }
>> 
>> My problem is that the following does not correctly render thing 2 and 4.
>> 
>>        public String onMyEvent() {
>> 
>>                thing = getThing(2);
>>                zoneIndex = 2;
>>                ajaxResponseRenderer.addRender(thingZone);
>> 
>>                thing = getThing(4);
>>                zoneIndex = 4;
>>                ajaxResponseRenderer.addRender(thingZone);
>> 
>>                thing = null;
>> 
>>        }
>> 
>> As you can see below, the response includes the right zone names, but the
>> rendered content of them is the same and is based on whatever the final
>> values were. In this case the final value of thing was null, so white space
>> was rendered into both zones.
>> 
>> {
>>  "_tapestry" : {
>>    "content" : [
>>      [
>>        “thingZone_4",
>>        "\n\t\t\t\t\t\t\t\t\n\t\t\t\t"
>>      ],
>>      [
>>        “thingZone_2",
>>        "\n\t\t\t\t\t\t\t\t\n\t\t\t\t"
>>      ]
>>    ],
>>    "inits" : [
>> 
>> So addRender(ClientBodyElementZone zone) queues up the request for later.
>> Can I somehow queue up each request with the current values that I want it
>> to use when rendering?
>> 
>> Cheers,
>> 
>> Geoff
> 
> 
> 
> -- 
> Dmitry Gusev
> 
> AnjLab Team
> http://anjlab.com


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


Re: Updating specific zone instances in a loop.

Posted by Dmitry Gusev <dm...@gmail.com>.
Hi Geoff,

You can pass an instance of the RenderCommand that could capture the
context, hopefully this snippet can give a hint.

Regards,
Dmitry

for (int i = 0; i < emailIds.length; i++)
{
    String emailId = emailIds[i];
    boolean display = displayStatusArray[i];

    // Set tempId for getEmailStatusZoneId()
    tempId = emailId;

    // There may be multiple instances of this component being
refreshed at the same time,
    // so we need to render it immediately
    ajaxResponseRenderer.addRender(getEmailStatusZoneId(),
(RenderCommand) (writer, queue) -> {
        // Initialise before rendering
        EmailDeliveryStatus.this.tempId = emailId;
        EmailDeliveryStatus.this.show = display;
        setupEmail();

        ((RenderCommand) emailStatusZone.getBody()).render(writer, queue);

        initJavaScript();
    });
}



On Tue, Jan 3, 2023 at 2:47 PM JumpStart <
geoff.callender.jumpstart@gmail.com> wrote:

> Hi all,
>
> Let’s say I have loop around a zone, and on a particular event I want to
> render just the 2nd and 4th instances of the zone. How do I do that?
>
>         <t:loop source="1..10" value="zoneIndex">
>
>                 <t:zone t:id=“thingZone" id="prop:zoneId” >
>                         <!— Contents from thing goes here. —>
>                 </t:zone>
>
>         </t:loop>
>
>         @Property
>         private int zoneIndex;
>
>         @InjectComponent
>         private Zone thingZone;
>
>         public String getZoneId() {
>                 return “thingZone_" + zoneIndex;
>         }
>
> My problem is that the following does not correctly render thing 2 and 4.
>
>         public String onMyEvent() {
>
>                 thing = getThing(2);
>                 zoneIndex = 2;
>                 ajaxResponseRenderer.addRender(thingZone);
>
>                 thing = getThing(4);
>                 zoneIndex = 4;
>                 ajaxResponseRenderer.addRender(thingZone);
>
>                 thing = null;
>
>         }
>
> As you can see below, the response includes the right zone names, but the
> rendered content of them is the same and is based on whatever the final
> values were. In this case the final value of thing was null, so white space
> was rendered into both zones.
>
> {
>   "_tapestry" : {
>     "content" : [
>       [
>         “thingZone_4",
>         "\n\t\t\t\t\t\t\t\t\n\t\t\t\t"
>       ],
>       [
>         “thingZone_2",
>         "\n\t\t\t\t\t\t\t\t\n\t\t\t\t"
>       ]
>     ],
>     "inits" : [
>
> So addRender(ClientBodyElementZone zone) queues up the request for later.
> Can I somehow queue up each request with the current values that I want it
> to use when rendering?
>
> Cheers,
>
> Geoff



-- 
Dmitry Gusev

AnjLab Team
http://anjlab.com