Tuesday, November 23, 2010

GrailsExceptionResolver null pointer exception

This is the message I got after I hit a button in the gsp with an action="waiver".

23.11.10 09:36:35.054] ERROR errors.GrailsExceptionResolver - null
java.lang.NullPointerException
at java.lang.Thread.run(Thread.java:619)

I had a hard time to figure out this problem. The associated controller had an action:

def waiver = {
}

and the waver.gsp exists.

Now why did the exception happen? The reason was, because the controller has a method called getWaiver().

Friday, November 19, 2010

Log4J problem after deployment to Tomcat

The problem not happens on STS with Jetty.

By mistype a log statement, instead of:
log.debug("....")
typed
Log.debug("...."), oops that's wrong!!
this was the cause for an exception on the tomcat server:

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org.mortbay.log.Log
org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet.doDispatch(GrailsDispatcherServlet.java:318)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:70)
org.codehaus.groovy.grails.web.util.WebUtils.forwardRequestForUrlMappingInfo(WebUtils.java:293)
org.codehaus.groovy.grails.web.util.WebUtils.forwardRequestForUrlMappingInfo(WebUtils.java:269)
org.codehaus.groovy.grails.web.util.WebUtils.forwardRequestForUrlMappingInfo(WebUtils.java:261)
org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter.doFilterInternal(UrlMappingsFilter.java:181)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter.obtainContent(GrailsPageFilter.java:171)
org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter.doFilter(GrailsPageFilter.java:110)
org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:65)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
root cause
java.lang.NoClassDefFoundError: org.mortbay.log.Log
SocService$_save_closure1.class$(SocService.groovy)
SocService$_save_closure1.$get$$class$org$mortbay$log$Log(SocService.groovy)
SocService$_save_closure1.doCall(SocService.groovy:86)
SocService.save(SocService.groovy:44)
SocService$$FastClassByCGLIB$$830c874e.invoke()
net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
SocService$$EnhancerByCGLIB$$277a9fbf.save()
SocService$save.call(Unknown Source)
DocumentEditController$_closure2_closure33_closure117.doCall(DocumentEditController.groovy:997)


Config.groovy entries:
// log4j configuration
log4j = {
appenders {
console name: 'stdout', layout: pattern(conversionPattern:'%d{[dd.MM.yy HH:mm:ss.SSS]} %-5p %c{2} %x - %m%n')
rollingFile name: 'file', layout: pattern(conversionPattern:'%d{[dd.MM.yy HH:mm:ss.SSS]} %-5p %c{2} %x - %m%n'), file: 'fab.log'
}
root {
error()
additivity = true
}

error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails."web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails."web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.springframework',
'org.hibernate'

debug file:['grails.app']
'org.hibernate'
//stdout:'grails.app'

warn 'org.mortbay.log'

}

Saturday, January 30, 2010

GrailsUI.datePicker versus RichUI.dateChooser

The issue is, to work with and control the tab key from the keyboard and get a reference to the id param in the tag richui:dateChooser or gui:datePicker.

e.g:
< onfocus="document.getElementById('filingDate').focus();" tabindex="1">
< id="filingDate" name="filingDate" formatstring="MM/dd/yyyy">
< /td >

In both plugins the id is documented, but only GrailsUI works. RichUI generates an artifical id and no reference is possible. The work with tab key in GrailsUI is more predictable than in RichUI.

Another difference between RichUI and GrailsUI is, how the params are delievered to a command object:
In RichUI: filingDate = "struct"
filingDate_month = "01"
filingDate_day = "30"
filingDate_year = "2010"

In GrailsUI: filingDate = "01/30/2010"

Additional tip:
RichUI don't modifies the page layout.
GrailsUI does. To prevent this following modifications can be made:

1. In main.gsp - move "g:layoutHead" before link to the css
< rel="stylesheet" href="${createLinkTo(dir:'css',file:'main.css')}" >

2. In the app gsp, put this line
gui:resources components="['datePicker']"
as first line after the head tag

3. Overwrite GailsUI grails-ui.css in own css file:
.datefield {
position:relative;
top:0px;
left:0px;
white-space:nowrap;
width:25em;
padding:0px 10px 0px 0px;
}

.datefield input {
width:75px;
}