my log.info(...) in GSP just does not come out in my log files, why ? It just took so long to figure out. Is there a better way? - grails

Recently I wasted a stupendous amount of time when I had a GSP page crashing for a user.
Essentially request.user.currRole().name was crashing within the GSP page. .user was null. Not sure why, still figuring that out hence, I decided to do some logging.
So, I turned on logging by the doing the following ...
<%# page import="org.apache.log4j.*" %>
<%
final Logger log = Logger.getLogger(this.getClass());
%>
Then somewhere further down my page I had the following line to tell me if the value was null or not
<% log.info(" request.user=${request.user}"); %>
For these logs to come out I amended my Config.groovy like so, after spending ages going thru countless of grails documentation & stackoverflow posts
info 'grails.app','org.codehaus.groovy.grails.web.pages'
I assumed that somehow my GSP hung in a sub-tree package within the roots exposed in info above.
I was perplexed and angry as to why the logs just did not come out.
Only realizing after a long R&D stint that, that Groovy Page gets pre-compiled into a class that does not hang from any of the package roots mentioned in Config.groovy (unlike JSPs where they get parsed and compiled classes at the Tomcat server end) and that class is called gsp_motorSystem_motorDeptedit_gsp
It worked when I did the following ...
info 'grails.app','org.codehaus.groovy.grails.web.pages',
'gsp_motorSystem_motorDeptedit_gsp'
Questions
Could there have been a better or a less time-consuming way (Grails & Groovy are supposed to alleviate the verbosity of Java but I find the brevity of Groovy makes the coder think far too much about what is really happening in the code and it thus becomes a maintainability nightmare anyways)
Was there a log object available in GSPs like there are in Grails Controllers & Service objects ?
Should I have used final Logger log = Logger.getLogger("motordept.edit.gsp") and then amended Config.groovy like so
info 'grails.app','org.codehaus.groovy.grails.web.pages',
'motordept.edit.gsp'
Or is this my weak understanding of best practice for log4j usage in JSPs or GSPs in this case

Related

magento unable to reroute to controller in config.xml

(FYI this is version 1.4, and yes I'm flushing my var/cache folder. I've started reading through Alan Storm's tutorials and that helped, but nothing specific on this problem)
I am new to Magento, we are using the OnePage checkout method, and we have the following:
app/code/local/Ourcompany/Checkout/etc/config.xml
Which has the following definition:
<frontend>
<routers>
<checkout>
<args>
<modules>
<Ourcompany_Checkout before="Mage_Checkout">Ourcompany_Checkout</Ourcompany_Checkout>
</modules>
</args>
</checkout>
</routers>
</frontend>
I have a corresponding file in:
/app/code/local/Ourcompany/Checkout/controllers/OnepageController.php
In there I have a class:
class Ourcompany_Checkout_OnepageController extends Mage_Checkout_OnepageController
So far I have not been able to get Magento to acknowledge it's there. The native methods in core are being called only. If I remove or rename this page, there is no error statement - I think my syntax in config.xml is not correct. Can anyone identify the improper syntax present?
This is the first time I have answered my own question but I think the answer here is noteworthy. The CommerceBug debugger was very useful as I was able to look at classes that were loaded. As it turns out, there was another module that had been created, called Admaster which got precedence as the router for the OnepageController.
I'm sure dealing with this type of conflict is common for Magento, so I have a mental checklist item now if this happens again.

ist there something like __FILE__ in coffeescript at 'compiletime'?

The question:
How do I get somthing like that in coffeescript
modules_list[some_calculation(__FILE__)]=a_local_class.new
I have a module manager, that handles all my coffeescripts (js) at runtime - i.e. while in browser, that means:
I have
many modules, not all are in all situations loaded 'statically'
only some have dependencies
module manager resolves things like init and dynamic reload (ajax)
and dynamic init
A module looks like this in prinzip:
class Book
constructor: ->
...
init: =>
$$$.get_module('BookReader') #<- ajax loaded if not already
later_on: =>
$$$.get_module('LetterCounter').count_letters(#) #<- ajax loaded if not already
...
#$$$.modules_list['Book'] = ->
new Book
this all works (very) satisfying.
But I have a rendunancy in my Logic, because a 'module', has a module name, a class name and - thats the point - a file name
the class name is - thats clear - not a problem, I could name all 'Foo'. Its only not nice to do that.
But modulename ( modules_list['Book'] ) and the coffee- (js-) file name are redundant in sence of Rails CoC.
Any ideas how to get
#$$$.modules_list[some_calc(__FILE__)] = -> new Book
i was there, and there may be a solution for me, but if, I dont understand it.
thanks in advance
ps.: for those who want to know "why I do this":
I have 3 completely different apps for 3 different customers, I am far away to say what is the base for all, 2 apps a realy big with a huge amount of js, that is not always needed so I want to reload it dynamicaly. I "help" asset pipeline a bit with putting all files (staticaly) used in a single one without the ones I was working on the last 20 mins (dynamicaly) for better debugging, and I get rid of all (down-)load ordering problems
There is no need for __FILE__or something like that, in that case. I see that now. It would be the wrong direction of naming.
Its the same 'problem' that you have with Rails it self. If you have
module Base
class Fun
your filename should be base/fun.rb not vice versa!
The Filename resolves out of "its content" not the other direction.

Rails 3.2 + CoffeeScript + Namespacing + Separate Files = Confusion

I have one companion script file for a Rails model, that uses code I've broken down into a hierarchy of over a dozen classes, for things like jQuery/Bootstrap UI code, factoring out similarities between different types of dialog, and so on. Let's say I'm working with articles.js.coffee as the "main page script" here.
I can define Coffeescript classes, namespace them as something like window.ourproject.OurUIDialog, and save them in separate, per-class source files such as app/assets/javascripts/OurUIDialog.js.coffee. Restart the Rails server, and that class can be subclassed, e.g., window.ourproject.PostInfoDialog extends window.ourproject.OurUIDialog. As long as PostInfoDialog is in articles.js.coffee (where the instantiation of the PostInfoDialog is), all is well.
But, if I move the subclass (PostInfoDialog) out into a separate file, e.g., PostInfoDialog.js.coffee, then attempting to do anything at all with it within the main articles script produces
Uncaught TypeError: Cannot read property 'prototype' of undefined
Again:
This revolves around a Rails model's companion script file, here called articles.js.coffee;
window.ourproject.OurUIDialog gets picked up whether it's in its own file or in articles.js.coffee
window.ourproject.PostInfoDialog (which extends OurUIDialog) can only be used if it's not in a separate file, even though viewing the generated HTML shows PostInfoDialog being included with all the other script files.
I'm tearing my hair out trying to figure this out, and I didn't have much left to begin with. Any ideas?
Pretty sure that Trevor Burnham answered my question when he answered this one; I just didn't see it the first dozen times I searched. :-P
Thanks to both of you for reading this one, though. :-)

IntelliJ Idea auto-complete for my own grails domain meta class methods?

I'm using IntelliJ Idea 10 IDE for my grails development and while it's great at working out the "standard" meta class methods on, for example, domain classes (save, findBy etc), it (obviously) can't pick up methods added by plugins or my own code.
While I don't expect the IDE to be able to pick these up automatically, I'm optimistically wondering if there's a way to tell IntelliJ that, for example, "myMethod" is added to all domain objects, and that it takes a map and returns "myType".
It's a long shot I know, but does anyone know how this might be done in config, a plugin, or by some smoke-and-mirrors so I can a) stop missing simple, stupid typos and b) get some auto-complete?
I think you're looking for the GroovyDSL scripting framework
http://confluence.jetbrains.net/display/GRVY/Scripting+IDE+for+DSL+awareness
its possible to save a *.gdsl file somethere in src dir, with content:
contributor(context()) {
def scope = com.intellij.psi.search.GlobalSearchScope.allScope(project);
delegatesTo(com.intellij.psi.JavaPsiFacade.getInstance(project).findClass('org.grails.datastore.gorm.GormStaticApi', scope)) delegatesTo(com.intellij.psi.JavaPsiFacade.getInstance(project).findClass('org.grails.datastore.gorm.GormEntity', scope))}

Urlmapping for camel case with more than one meaningful step

As we know, grails automatically maps MyController to [root]/my as expected, but if I have MyAnotherController it gets mapped to [root]/myAnother. I would like to get it mapped automatically to [root]/my/another.
Is there a way to do this without putting additional URL mapping directives to conf/UrlMappings.groovy?
There is an open JIRA related to this (placing controllers in sub folders/ packages). Go ahead and vote for it. I would love to see this implemented in Grails.
http://jira.codehaus.org/browse/GRAILS-1243

Resources