TO THE NEW Blog PAGES

Grails

Create transients using formula in Grails

I would explain this through a use case of my own project. A Program has many AdvertisingMaterial and we have subclasses of AdvertisingMaterial, FlashAd, ImageAd etc. The user wants the ability to filter the programs which had flashAds, imageAds etc. This required filtering on the basis of the class property that we have in the database […]

Grails

Request Mocking to use groovyPagesTemplateEngine in backend threads

We have a setup where a backend thread, fired by the Spring Events, does some processing, generates a PDF and emails the result to the user. The code we were using to generate the HTML from a GSP to be converted to a PDF using iText was as follows : [java] def webRequest = RequestContextHolder.getRequestAttributes() […]

Vivek Krishna
Vivek Krishna
Read

Technology

Sleep in Jquery.

Few days earlier, for achieving “Thread.sleep()” functionality in Jquery, I use javascript’s “setTimeout()” method. I found that Jquery has a finer and better way for doing this, The “delay()” method Example: If I want to show an element after 1000 mili seconds then I would do it in following way: $(“div .heading”).delay(1000).show() Hope this little […]

Chandan Luthra
Chandan Luthra
Read

Grails

Posting messages on facebook wall using graph api

Firstly ,you need to connect with facebook. Once you have facebook access token you can post messages on the facebook wall using the below code. void postMessage(String facebookAccessToken, String message, String facebookId) { StringBuilder stringBuilder = new StringBuilder(“access_token=”); stringBuilder.append(URLEncoder.encode(facebookAccessToken, “UTF-8”)); stringBuilder.append(“&message=”); stringBuilder.append(URLEncoder.encode(message, “UTF-8”)); URL url = new URL(“https://graph.facebook.com/${facebookId}/feed”); HttpURLConnection connection try { connection = (HttpURLConnection) […]

Anshul Sharma
Anshul Sharma
Read

Grails

Multiple Variable Assignment in Groovy

In one of my project, I was in need to return multiple variables from a method. I searched and found very good Groovy way for ‘Multiple Assignment’, This allows us to assign multiple variables at once. [groovy]def (str1,str2,str3) = [‘Groovy’,’and’,’Grails’] assert str1 == ‘Groovy’ && str2 == ‘and’ && str3 == ‘Grails'[/groovy] We can have […]

Ankur Tripathi
Ankur Tripathi
Read

Technology

Local Storage (html5)

HTML5 storage provides a way for websites to store information on your computer and retrieve it later. The concept is similar to cookies, but cookies do not store larger quantities of data. Cookies are limited in size, and your browser sends a request to the web server every time a new request is initiated (which […]

Umar
Umar
Read

Grails

Number Formating using regular expression and format method of String class

Hey guys, I found something very useful, so sharing it here. In one of my project there was a requirement to create a fixed length user-id. Let’s say it was 5 characters ID. So in other words we required to convert – ‘123’ to ‘00123’ and ‘1000’ to ‘01000’ and ‘12345’ will remain ‘12345’. It […]

Salil
Salil
Read

Grails

Using Custom Tag for embedding the Video in Grails

I had to make a video available on my GSP page. So I looked at the grails flash-player plugin.  After going through the documentation I found that it could not be used with videos on YouTube. This code given below will generate the script for the flash player on your GSP for playing youtube videos. [html] […]

Anuj Aneja
Anuj Aneja
Read

Technology

Database Backup Script for windows

In one of the project I am working on, the application needs to be deployed on windows server. To take the database backup, I wrote the script which does the following : Takes database dump and copy it to the backup folder. Zip that backup file and rename it to the format “YYYYMMDD_HHMMSS” Removes  all […]

Amit Jain
Amit Jain
Read

Grails

Using Groovy MOP and Closure to prevent expression evaluation in logger.debug()

Generally in our code, we have lots of debug statements that prints the intricate details of the state of the program. Infact, the debug statements are meant for doing this. Sometimes, these debug statements may contain a call to some other method to evaluate what is to be logged. [java] //Logging statement calling some function […]

Mohd Farid
Mohd Farid
Read

Grails

Recursively searching for similar files on file-system in groovy

Hi, In my recent grails project, i needed to find the existence of particular files on file system. I needed to search in a directory and all of its subdirectories and look into them if the files with the given format exists in it or not. If the files exists, then it should return the […]

Vishal Sahu
Vishal Sahu
Read

Grails

MalformedByteSequenceException with Grails jasper plugin 1.1.6

Hi All, I was facing a lot of problems with creating pdf reports using jasper plugin 1.1.6 in grails, Though I had earlier worked with 0.9.5 and 0.9.7 versions of the plugin with a lot of ease but some how 1.1.6 version of plugin was not generating reports  it always ended up throwing MalformedByteSequenceException: Invalid […]

Sachin
Sachin
Read