Friday, September 13, 2013

How to Display Date and Time in your Grails Application

I am going to show you how you can accept Data and Time from the user as input using 'Jquery Date Time Picker Plugin'.

You can read more about the plugin here.

Step 1:

In BuildConfig.groovy, add the following code in plugins tag as:

plugins { 
    compile ":jquery-ui:1.8.24" 
    compile ':jquery-date-time-picker:0.1.0'

Step 2:

In Config.groovy, add the following code:

Monday, September 9, 2013

DiffMerge : A Merging tool for Git

When using the distributed Version Control i.e. Git, your files might conflict since multiple users might have been working on same file.

Hence, you can use any text editor which is boring, tiresome and hard to identify where the issue is. The best option is to use a merging tool such as Diff Merge. (Click on the link to go to the downloads page)

I faced one configuration issue when I was trying to use it for the first time.
The error was "Unexpected Parameter". The configuration from the software manual didnot work for me.

The solution is to edit the .gitconfig file manually to look like the following.

The following commands in a Command Prompt window will update your .gitconfig to configure GIT use DiffMerge:

C:\> git config --global diff.tool diffmerge
C:\> git config --global difftool.diffmerge.cmd "C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe \"$LOCAL\" \"$REMOTE\""

C:\> git config --global merge.tool diffmerge
C:\> git config --global mergetool.diffmerge.trustExitCode true
C:\> git config --global mergetool.diffmerge.cmd "C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe  --merge --result=$MERGED $LOCAL $BASE $REMOTE" trustExitCode = true keepBackup = false

The code snippet that is Bold is the major change made.

Grails : Displaying Error Message on View which is thrown from the Service Layer

In your controller class, enclose the code that calls the service in a try-catch block.

try {

def searchResult = User.getUserByName(

if(searchResult != null)
render(view: "/admin/user/list", model: [userInstanceList: searchResult?.results, userInstanceTotal: searchResult?.total])


flash.message = message(code: 'user.nonfound.message', default: "No items found.")
render(view: "/admin/user/list", model: [userInstanceList: [], userInstanceTotal: 0])
} catch (e) {

flash.message = message(code: 'user.nonfound.message', default: "No items found.")

render(view: "/admin/user/list", model: [userInstanceList: [],userInstanceTotal: 0])

Wednesday, September 4, 2013

Sending Email from your Grails Application : A Tutorial

Here is how you can simply send an email from your Grails Application.

Step 1: In BuildConfig.groovy add the ff code in plugins{} tag,

// Grails mail plugin
compile ":mail:1.0.1"

Step 2: In Config.groovy, add the ff code
grails {
mail {
host = ""
port = 465
username = ""
password = "fakeP@SSw0Rd"
props = ["mail.smtp.auth":"true",

Solving: "No result defined for action ... and result input"

When programming in Java and using the Struts 2 Framework, the program threw the exception "No result defined for action ... and result input".

The solution was to add an input redirection like.

<result type="dispatcher" name="input">/WEB-INF/jsp/pc/agent/myJSP-page.jsp</result>