Skip to main content

developerWorks >  WebSphere  >  Forums  >  IBM Lotus Widget Factory  >  developerWorks

passing a variable to a contained model    Point your RSS reader here for a feed of the latest messages in this thread


     

 
 

My developerWorks
 Welcome, Guest
Sign in or register
Permlink Replies: 3 - Pages: 1 - Last Post: Oct 26, 2009 1:46 PM Last Post By: mtr Threads: [ Previous | Next ]
rob02

Posts: 13
Registered: Jul 30, 2009 10:22:34 AM
passing a variable to a contained model
Posted: Oct 26, 2009 07:07:51 AM
Click to report abuse...   Click to reply to this thread Reply
Hi,
I've placed a 'model container' inside a repeated region but I cannot pass the loop variable to the model involved in the container...

any suggestion?
mtr

Posts: 869
Registered: May 14, 2006 12:02:13 PM
Re: passing a variable to a contained model
Posted: Oct 26, 2009 09:28:48 AM   in response to: rob02 in response to: rob02's post
Click to report abuse...   Click to reply to this thread Reply
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.
rob02

Posts: 13
Registered: Jul 30, 2009 10:22:34 AM
Re: passing a variable to a contained model
Posted: Oct 26, 2009 12:16:02 PM   in response to: mtr in response to: mtr's post
Click to report abuse...   Click to reply to this thread Reply
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?
mtr

Posts: 869
Registered: May 14, 2006 12:02:13 PM
Re: passing a variable to a contained model
Posted: Oct 26, 2009 01:46:52 PM   in response to: rob02 in response to: rob02's post
Click to report abuse...   Click to reply to this thread Reply
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
Help

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.

 

MoreLess 


Point your RSS reader here for a feed of the latest messages in all forums