Question
· Feb 14, 2017

Looking for Best Zen MVC Recipe for Passing "View" Data to DataModel and Form...

...in order to initialize the data model and form with data from another object.

Our Zen MVC project recently had an issue with a child object being assigned to multiple parent objects (the design calls for one parent per child). The root cause of this issue was the use of a %session variable to pass the ID of the parent object to the OnLoadModel method of the DataModel associated with the child object. The goal is to use the ID to open the parent object and use some of its fields to populate default fields in the child and the child’s form. Editing multiple parents in Zen pages in tabbed windows of the same browser and saving a child object in one of the tabs while the session variable contained the ID of another parent caused these rare but troublesome bad assignments.

While looking through google groups and the community site, I found multiple instances of the use of %session variables to get information from the View to the DataModel but could not find other “recipes” to do this that avoided the issue we found. After discussing alternatives with other members of the team, I’ve tried the following:

  • Using a global (e.g., ^OpportunitySeed) to hold the parent ID, setting it in the View’s “%OnAfterCreateComponent” and getting it in “%OnNewSource” of the DataModel.
  • Using the %page variable (the parent ID was already being stored as a property on the page, coming in as a URL parameter).
  • Using a %request variable (again, setting it in the View and getting it in the DataModel).

All of the above work, although the last two alternatives “feel” better than the first. We’ve gone with %page approach for now, pending any better ideas from the community. We’ve also moved the “initialize a new instance” code from %OnLoadModel (removing a ..%id check) to %OnNewSource.

Do the Zen MVC users/developers out there have other better alternatives? Since the parent ID is part of the child data model, I’ve also spent some time experimenting with “setDataByName” and “%SetDataByName” methods of the dataController, but have had no success.

Please let me know if you need me to clarify anything about the issue. Thanks all!

Discussion (1)1
Log in or sign up to continue