|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Passing values to a viewHi all and excuse me if a dumb question but...
Let's say I have two views (EmployeeView and CustomerView) with a common part that shows personal information and I create a common view file to deal with if (dspPersonInfo.cfm). <event-handler name="employee.info"> <broadcasts> <message name="NeedEmployee" /> </broadcasts> <views> <include name="personInfo" template="dspPersonInfo.cfm"> <value name="person" value="??????????" /> </include> <include name="employeeView" template="dspEmployeeView.cfm" /> </views> <results> <result do="view.template" /> </results> </event-handler> <event-handler name="customer.info"> <broadcasts> <message name="NeedCustomer" /> </broadcasts> <views> <include name="personInfo" template="dspPersonInfo.cfm"> <value name="person" value="??????????" /> </include> <include name="customerView" template="dspCustomerView.cfm" /> </views> <results> <result do="view.template" /> </results> </event-handler> Before calling the views I send a message to get the Employee or Customer info (NeedEmployee / NeedCustomer). These messages call two different controller methods that write into event/viewstate two different variables (employee or customer). <function name="getEmployee" ...> ... <cfset event.setValue("employee", local.employee)> </function> <function name="getCustomer" ...> ... <cfset event.setValue("customer", local.customer)> </function> The question is: is it possible to pass a variable value in <include name="personInfo" template="dspPersonInfo.cfm"> <value name="person" value="??????????" /> </include> instead of a literal? The only workaround I can think about is passing to the view not the value but the name of the event variable that contains the value (i.e. passing "employee" or "customer") but I don't like this very much as I don't consider this natural when writing the dspPersonInfo view. Thanks for the help, Jesús --^---------------------------------------------------------------- This email was sent to: lists@... EASY UNSUBSCRIBE click here: http://topica.com/u/?b1drHn.b8CODV.bGlzdHNA Or send an email to: modelglue-unsubscribe@... For Topica's complete suite of email marketing solutions visit: http://www.topica.com/?p=TEXFOOTER --^---------------------------------------------------------------- |
|
|
Re: Passing values to a viewJesús,
I'm not a model-glue "pattern guru" by any means, so please take this with a grain of salt :) I would consider: 1. make the dspPersonInfo.cfm have a if/elseif so you can determine whether you have a customer or employee object. Something like: <cfif viewState.Exists("customer")> //fetch the customer, do some customer view stuff here <cfelseif viewState.Exists("employee")> //fetch the employee do some employee view stuff here </cfif> (optionally you could wait and do view stuff here, depending on how different customer and employee are for this view) or 2. you could create two partial view templates, dspCustomerInfo.cfm and dspEmployeeInfo.cfm, each being specialized to deal with their respective types of people. Since model-glue allows you to name partial views, your layout page could still just output the "personInfo" from the viewCollection. or 3. Use the argument you're passing to the view (from ModelGlue.xml) and then fetch the object accordingly: <cfset personType = viewState.GetValue("person") /> <!--- get the literal passed from ModelGlue.xml ---> <cfset objMyPerson = viewState.GetValue(personType) /> <cfoutput> <p>Hello, #objMyPerson.getFirstName()# #objMyPerson.getLastName()#</p> </cfoutput> .. hope that helps! On May 7, 2007, at 4:58 AM, jesupi@... wrote: > Hi all and excuse me if a dumb question but... > > Let's say I have two views (EmployeeView and CustomerView) with a > common > part that shows personal information and I create a common view > file to > deal with if (dspPersonInfo.cfm). > > <event-handler name="employee.info"> > <broadcasts> > <message name="NeedEmployee" /> > </broadcasts> > <views> > <include name="personInfo" template="dspPersonInfo.cfm"> > <value name="person" value="??????????" /> > </include> > <include name="employeeView" template="dspEmployeeView.cfm" /> > </views> > <results> > <result do="view.template" /> > </results> > </event-handler> > > <event-handler name="customer.info"> > <broadcasts> > <message name="NeedCustomer" /> > </broadcasts> > <views> > <include name="personInfo" template="dspPersonInfo.cfm"> > <value name="person" value="??????????" /> > </include> > <include name="customerView" template="dspCustomerView.cfm" /> > </views> > <results> > <result do="view.template" /> > </results> > </event-handler> > > Before calling the views I send a message to get the Employee or > Customer info (NeedEmployee / NeedCustomer). These messages call two > different controller methods that write into event/viewstate two > different variables (employee or customer). > > <function name="getEmployee" ...> > ... > <cfset event.setValue("employee", local.employee)> > </function> > > <function name="getCustomer" ...> > ... > <cfset event.setValue("customer", local.customer)> > </function> > > > The question is: is it possible to pass a variable value in > > <include name="personInfo" template="dspPersonInfo.cfm"> > <value name="person" value="??????????" /> > </include> > > instead of a literal? > > The only workaround I can think about is passing to the view not the > value but the name of the event variable that contains the value (i.e. > passing "employee" or "customer") but I don't like this very much as I > don't consider this natural when writing the dspPersonInfo view. > > Thanks for the help, > > Jesús > > > > > -- > BEGIN-ANTISPAM-VOTING-LINKS > ------------------------------------------------------ > > Teach CanIt if this mail (ID 297627046) is spam: > Spam: https://antispam.osu.edu/b.php? > c=s&i=297627046&m=ecfafb79d2ee > Not spam: https://antispam.osu.edu/b.php? > c=n&i=297627046&m=ecfafb79d2ee > Forget vote: https://antispam.osu.edu/b.php? > c=f&i=297627046&m=ecfafb79d2ee > ------------------------------------------------------ > END-ANTISPAM-VOTING-LINKS > --^---------------------------------------------------------------- This email was sent to: lists@... EASY UNSUBSCRIBE click here: http://topica.com/u/?b1drHn.b8CODV.bGlzdHNA Or send an email to: modelglue-unsubscribe@... For Topica's complete suite of email marketing solutions visit: http://www.topica.com/?p=TEXFOOTER --^---------------------------------------------------------------- |
|
|
|
| Free Forum Powered by Nabble | Forum Help |