You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Peter Hvass <P....@albourne.com> on 2013/05/02 14:25:30 UTC

[5.3] Mixin Base Class Affecting Initializer Parameters When In A Loop

Hello, 


I'm trying to debug some strange behaviour; wondering if anyone can offer any advice! I've provided sample semi-pseudo code 
below. The issue is that when putting the containing component's client id into the parameters JSONObject by using ComponentResources.getContainer 
in the MixinBase, subsequent calls to JavascriptSupport.addInitializerCall (while looping over components with this mixin applied), 
carry the correct client id in their parameters but will then somehow manage to overwrite all client ids in the parameters of all previous 
initializations of this mixin in the loop. 


I'm using MixinBase to remove some boilerplate and shorten certain calls that we use in the majority of our mixins. 


JavascriptSupport.inits JSONObject looks something like this from call to call: 


1st iteration where container client id is "somecomponent", 
"amixin" : [ 
{ "clientId" : "somecomponent" } 
] 


2nd iteration where container client id is "somecomponent_0", 
"amixin" : [ 
{ "clientId" : "somecomponent_0" }, 
{ "clientId" : "somecomponent_0" } 
} 


And so on... 


Here's the code that goes with the above description: 
@Import(library = "amixin.js") 
AMixin extends MixinBase { 
// some parameters 
void initialize() { 
// add stuff to parameters JSONObject 'living in' MixinBase 
} 
} 


abstract MixinBase { 
JSONObject parameters; 


@SetupRender 
void initialize(); 


void afterRender() { 
// try to get clientId and add it to parameters via ComponentResources.getContainer().getClientId(); 
javascriptsupport.addInitializerCall(getClass().getSimpleName().toLowerCase(), getParameters()); 
} 


void put(String.. keysAndValues) { 
getParameters().put(keysAndValues); 
} 


private JSONObject getParameters() { 
if (parameters == null) parameters = new JSONObject(); 
return parameters; 
} 


} 


And then this is applied to components in a t:loop; 


PartOfSome.tml 
------------- 
<t:loop source="1..5"> 
<t:somecomponent t:mixins="amixin" /> 
</t:loop> 


Thanks in advance, 
Peter 

Re: [5.3] Mixin Base Class Affecting Initializer Parameters When In A Loop

Posted by Peter Hvass <P....@albourne.com>.
Hi Lance, 


I did know about 'static structure, dynamic behaviour' but now understand it better in practice. :) 


It was indeed the parameters field null check - this really helped illuminate how things actually operate. 


Thanks for the help!! Much appreciated! 


Peter 

----- Original Message -----

From: "Lance Java" <la...@googlemail.com> 
To: "Tapestry users" <us...@tapestry.apache.org> 
Sent: Thursday, 2 May, 2013 3:53:56 PM 
Subject: Re: [5.3] Mixin Base Class Affecting Initializer Parameters When In A Loop 

Do you realise that there is only 1 instance of the component and also 1 
instance of the mixin? And that the same component/mixin is fired for all 5 
iterations through the loop? 

It's part of tapestry's "static structure, dynamic behaviour". I think if 
you make sure to initialize all fields in setupRender() it should fix your 
issue. 
The null check in getParameters() might be the problem. 


Re: [5.3] Mixin Base Class Affecting Initializer Parameters When In A Loop

Posted by Lance Java <la...@googlemail.com>.
Do you realise that there is only 1 instance of the component and also 1
instance of the mixin? And that the same component/mixin is fired for all 5
iterations through the loop?

It's part of tapestry's "static structure, dynamic behaviour". I think if
you make sure to initialize all fields in setupRender() it should fix your
issue.
The null check in getParameters() might be the problem.