The cleanest way to communicate among models in a container relationship is to use a Factory event. In this sort of situation, the contained model could fire an event in a page OnLoad event handler for the main page, and assign the return value to a variable; in this case, the container model would listen for this event, and would return the current loop variable value from the handler.
For a case this simple, it might be easier to introduce a little more coupling between the container and contained models: a parent model can call a method (or action list, or LJO method, etc.) in a contained model. The Model Container builder adds a Linked Model connecting the contained model with the container - this Linked Model has the same name as the corresponding Model Container, except with "LinkedModel" added to the end. So to call a method named "setLoopVariableContext" in a model inside a Model Container named "InnerModel", the container model could use a reference like InnerModelModelContainer.setLoopVariableContext. Presumably, this method would be passed the loop variable info, and would stash the argument away in a variable.
I'm not sure I've understood...the contain*ED* model could fire an event in a page OnLoad event handler for the main page, and assign the return value to a variable; in this case, the contain*er* model would listen for this event, and would return the current loop variable value from the handler.
shouldn't be the opposite? I think the container should fire a send_loop_var event and the contained should listen to it and do the assignment...or not?
Having the container model fire the event will actually not work. There are two reasons that work together: 1) Model Container does a "lazy" load, not loading the model until it's being rendered and 2) Factory events are only delivered to model instances that exist at the time the event is fired (since there's no explicit "wiring", the event can't "know" what model instances might want to hear it.)
If the container were to fire the event, the first time the event was fired the contained model instance would not have been created yet, and so it would not have the correct data.
You could work around that using the Model Container "load" API, forcing the contained model instance to be created earlier than normal.
Tags
Use the search field to
find all types of content in My developerWorks with that tag.
Use the slider bar to see more or fewer tags.
Popular tags shows the top tags for this particular type of content or application that you're viewing.
My tags shows your tags for this particular type of content or application that
you're viewing.