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 

Reply via email to