How to easily render data from a controller

22 views
Skip to first unread message

Ryan Stille

unread,
Mar 5, 2014, 5:21:44 PM3/5/14
to model...@googlegroups.com
Hi all, I've been googling this for a while but haven't come up with anything...

I have an existing app, with a login. After logging in (the event is login.process) the user is redirect to a "home" event that takes quite a while to load. If they fail they are redirected to an event that shows a login form.

Now I want to allow for a desktop app to make calls to my app to log users in, then make http requests on their behalf. I'd like to have this desktop app use the same login event ("login.process"). This would work, but the desktop app doesn't get feedback without scraping through the returned HTML, and the returned HTML takes quite a while to return because this home page is a slow rendering page.

What I want to do is in the controller method (the one that is used by the login.process event), instead of checking credentials and forwarding to home, I want to check credentials AND THEN if a flag is passed (like Coming_from_desktop_app=true) just return 1 or 0 or something to indicate login success. With ColdBox is this is easy, I would just check for the flag and then event.renderData(data="1"), something like that. I haven't figured out how to do something near as graceful in MG.

I could add a new, separate event and controller method for the desktop app, but I'd rather not have to maintain that.

Thanks for any help.

Dan Wilson

unread,
Mar 5, 2014, 5:24:55 PM3/5/14
to model...@googlegroups.com

I'm away from my computer so i can't be more verbose,

But if you are using MG 3, check the answer on this page for request formats http://stackoverflow.com/questions/7369613/how-do-i-configure-coldfusion-model-glue-3-so-that-it-wont-redirect-on-ajax-req

--
--
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog
 
You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to model...@googlegroups.com
To unsubscribe from this group, send email to
model-glue+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en
---
You received this message because you are subscribed to the Google Groups "model-glue" group.
To unsubscribe from this group and stop receiving emails from it, send an email to model-glue+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Ryan Stille

unread,
Mar 6, 2014, 8:24:41 AM3/6/14
to model...@googlegroups.com
Thanks Dan. I am on MG3. That solution would require me to add an additional view I think, which I was trying to avoid. I ended up adding this to the controller:

      <!--- if calling as an API, such as from QQ3, then only return 1 or 0 instead of redirecting to other events --->
        <cfif YesNoFormat(arguments.event.getValue("quick"))>
       <cfif session.UserBean.getLoggedin() eq 1>
        <cfset local.output = 1 />
       <cfelse>
        <cfset local.output = 0 />
       </cfif>
        <cfcontent type="text/plain" variable="#ToBinary( Tobase64(local.output) )#"/>
        </cfif>

I would like to add a renderData() method, similar to what ColdBox has. It would be nice if I could make this available all controllers. I'd rather not modify the ModelGlue.unity.controller.Controller file, do you know if a way I can inject the method into all the controllers? If I could dynamically add it to ModelGlue.unity.controller.Controller before the other controllers are instantiated, that should work.

Or, if I add a renderData method to ModelGlue.unity.controller.Controller, would you accept a pull request to add that change MG?

Ryan Stille

unread,
Mar 6, 2014, 8:25:47 AM3/6/14
to model...@googlegroups.com
Actually in MG it might make more sense to have the renderData method inside the event argument, right?

Dan Wilson

unread,
Mar 6, 2014, 10:26:59 AM3/6/14
to model...@googlegroups.com
Maybe you want this, instead?

https://github.com/modelglue/modelglue-framework/wiki/How-To-Use-Remoting


DW



Thursday, March 06, 2014 8:24 AM
Wednesday, March 05, 2014 5:24 PM

I'm away from my computer so i can't be more verbose,

But if you are using MG 3, check the answer on this page for request formats http://stackoverflow.com/questions/7369613/how-do-i-configure-coldfusion-model-glue-3-so-that-it-wont-redirect-on-ajax-req

Wednesday, March 05, 2014 5:21 PM
Reply all
Reply to author
Forward
0 new messages