I can see how my statement "helpers were designed to be used with views, not controllers" could be taken to mean that using helpers in controllers is always a bad thing.
The message I intended to convey was that from my perspective at least, helpers were designed with presentation logic in mind and I think it's important to understand the value of helpers in the context of views before exploring ways to use them in the context of controllers. One notorious anti-pattern in MVC is to invoke business logic from within a view. However, views sometimes need to perform complex operations and it is good to be able to reuse the implementations for those operations where possible. Back in the Model-Glue 2 days the only way I knew to reuse complex presentation logic was by injecting beans into the event context, but it felt like a bit of a hack. When I upgraded to Model-Glue 3, I learned about helpers. Most of the examples I saw showed helpers as a way to encapsulate complex presentation logic, but I also saw in them a way to provide "read-only" access to my model. Helpers filled a big need I had in my views, and I was able to discontinue my previous practice of injecting beans into the event context. I suppose there are some complex operations that are equally applicable in controllers and views, so helpers would be a good place for those. I haven't yet had the need for such operations so I can't speak from experience on the matter. I'd love to learn how well this technique works in practice. I agree that "UDF libraries for views and controllers" is a concise way of explaining the role of Model-Glue helpers. However, as a fan of object-oriented programming and interface-oriented design I tend to avoid procedural concepts such as UDF libraries. Well thought-out libraries can be quite useful, but more often than not I've seen programmers throw UDFs for things from database access to data formatting to date functions to session management into a single file and call it a "library". Cheers, -- Dennis On Fri, Jun 4, 2010 at 12:51 PM, Ezra Parker <[email protected]> wrote: > While I definitely concur that login logic is a model concern, I do > not agree with the assertion that helpers should only be used in views > and not in controllers. From my perspective, the intention of the > helpers "scope" is to provide a way to easily access UDFs in either > views or controllers. > > As an arbitrary (and perhaps contrived) example, I could see using a > helper in a controller to format/massage data in the event before > handing it off to a service, or using it to populate an object via a > call to makeEventBean(). > > -- > Ezra > > > On Fri, Jun 4, 2010 at 7:56 AM, Dennis Clark <[email protected]> wrote: > > +1 on the idea of using a service bean instead of a helper for > implementing > > login logic. Helpers were designed to be used within views, not > controllers. > > Although it's not documented on the Wiki, the latest release of > Model-Glue > > supports bean injection into helpers. This means that if you want to > expose > > your login bean's logic in a view, you can create a login helper CFC and > > inject your login service bean into it. The helper then acts as an > adapter > > to expose the functionality of the bean that's relevant to views. > > I use this very technique in the Model-Glue login example code I used in > my > > recent NCDevCon presentation. I haven't released the code yet, but am > > planning to put it up on GitHub this weekend. I'll post something on this > > list when it's out. > > Cheers, > > -- Dennis > > > > > > On Wed, Jun 2, 2010 at 2:32 PM, David J Henry > > <[email protected]> wrote: > >> > >> Steve, > >> > >> Did you start with the skeleton ModelGlue3 project? What triggers the > >> call to your security controller in ModelGlue.xml? You say "getting > >> some errors lately". Did this error start after some kind of change? > >> > >> Personally I might put a function like IsLoggedIn() in a service > >> component somewhere in my model like /model/SessionService.cfc or / > >> model/services/SecurityService.cfc for example. I would use > >> ColdSpring and Bean Injection to make this service accessible from my > >> controller in the beans scope. > >> > >> See > >> > http://docs.model-glue.com/wiki/HowTos/HowToUseBeanInjection#BeanInjection > >> for more about Bean Injection > >> > >> I don't know enough about helpers to know why the helper scope > >> wouldn't be available on first request. If you can provide some more > >> details about your application I will try to reproduce the problem. > >> > >> ...or you could just come in to work extra early and hit the app > >> before your co-workers get there x) > >> > >> Cheers, > >> ~David > >> > >> On May 31, 4:33 am, steve82 <[email protected]> wrote: > >> > Hi everybody, > >> > > >> > I've build a Model-Glue application for my firm and we're getting some > >> > errors lately. We are currently using Model-Glue version 3.1.299. The > >> > error appears every morning. So I assume, that this is the time when > >> > Model-Glue first loads up for that day and stores a copy of itself in > >> > the application scope. > >> > > >> > The following error message appears: > >> > > >> > Oops! > >> > > >> > Message Element LOGINHELPER is undefined in a Java object of type > >> > class [Ljava.lang.String;. > >> > Detail > >> > Extended Info > >> > Tag Context C:\Inetpub\wwwroot\office\controller\Security.cfc (42) > >> > C:\Inetpub\wwwroot\lib\cf\frameworks\mvc\modelglue\ModelGlue\gesture > >> > \eventrequest\EventContext.cfc (326) > >> > C:\Inetpub\wwwroot\lib\cf\frameworks\mvc\modelglue\ModelGlue\gesture > >> > \eventrequest\EventContext.cfc (253) > >> > C:\Inetpub\wwwroot\lib\cf\frameworks\mvc\modelglue\ModelGlue\gesture > >> > \eventrequest\phase\Invocation.cfc (91) > >> > C:\Inetpub\wwwroot\lib\cf\frameworks\mvc\modelglue\ModelGlue\gesture > >> > \eventrequest\EventContext.cfc (180) > >> > C:\Inetpub\wwwroot\lib\cf\frameworks\mvc\modelglue\ModelGlue\gesture > >> > \ModelGlue.cfc (243) > >> > C:\Inetpub\wwwroot\lib\cf\frameworks\mvc\modelglue\ModelGlue\gesture > >> > \ModelGlue.cfm (83) > >> > C:\Inetpub\wwwroot\lib\cf\frameworks\mvc\modelglue\ModelGlue\gesture > >> > \ModelGlue.cfc (243) > >> > C.\Inetpub\wwwroot\office\index.cfm (50) > >> > > >> > The code in Line 42 in our Security Controller just tries to call a > >> > method from the LoginHelper.cfc that is stored in the helpers > >> > directory: > >> > > >> > <cfif NOT helpers.LoginHelper.isLoggedIn(sid)> > >> > <cfset arguments.event.addResult("notLoggedIn") /> > >> > <cfelse> > >> > <!--- creation of user object goes here ---> > >> > </cfif> > >> > > >> > It looks to me that Model-Glue tries to access the helpers scope but > >> > it's not initialized yet - instead CF treats it as a normal string > >> > variable. > >> > > >> > Any ideas about how this problem and how one could prevent this from > >> > happenig? Telling my colleagues that they have to be more patient in > >> > the morning when the app first load up doesn't work - i already tried > >> > that :-) > >> > > >> > Many thanks, > >> > > >> > Steve > >> > >> -- > >> 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 [email protected] > >> To unsubscribe from this group, send email to > >> [email protected]<model-glue%[email protected]> > >> For more options, visit this group at > >> http://groups.google.com/group/model-glue?hl=en > > > > -- > > 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 [email protected] > > To unsubscribe from this group, send email to > > [email protected]<model-glue%[email protected]> > > For more options, visit this group at > > http://groups.google.com/group/model-glue?hl=en > > -- > 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 [email protected] > To unsubscribe from this group, send email to > [email protected]<model-glue%[email protected]> > For more options, visit this group at > http://groups.google.com/group/model-glue?hl=en > -- 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/model-glue?hl=en
