Showing posts with label Grails. Show all posts
Showing posts with label Grails. Show all posts

Oct 11, 2012

Show GSP directly in Grails 2

Posted Oct 11, 2012
Starting Grails 2.0, you cannot access GSP's directly when you type it in the url without defining it in url mappings. It has been disallowed since it's considered a security flaw of Grails 1.x. The side-effect is for simple static pages, it's a hassle to create mappings everytime.

Fortunately, Grails allows a simple workaround by using the UrlMappings.groovy. You just need to define one controller and make its actions accessible in url mappings configuration.

These are the steps I followed to quickly see all my root pages:
  1. Create a StaticViewController
  2. My UrlMappings.groovy contains:
     "/"(controller:"staticView")
     "/$action"(controller:"staticView")

Creating a controller is my preferred way, it's an additional step but my views are more manageable this way. 

For this example, I defined the following in my StaticViewController:
def index() {
}

def hello() {
}

Then added the ff gsps:
views/staticView/index.gsp
views/staticView/hello.gsp

I can now access the following in my browser:
http://localhost:8080/[app]/
http://localhost:8080/[app]/hello

To make your urls more search engine friendly, you may also want to map urls that ends in "html" to your controller, just add this line in UrlMappings.groovy :
"/*.html"(controller:"staticView")

In this case, I'll be able to access:
http://localhost:8080/[app]/hello.html

---
src: http://grails.1312388.n4.nabble.com/Direct-linking-to-gsp-in-Grails-2-0-td4228929.html

May 15, 2012

Grails Session Timeout

Posted May 15, 2012
To increase or decrease the default session time-out in grails:

In your project folder, first execute (if you haven't execute this yet):
grails install-templates

After this, you'll be able to see your web.xml in [project folder]/src/templates/war/

Add / modify the code in web.xml

<session-config>
   <session-timeout>60</session-timeout>
</session-config>

I place the snippet above after my servlet-mapping. The value "60" is in minutes.

Tested on Grails version 2.03. Enjoy!

Apr 10, 2012

Switching from Development to Production mode STS + Grails + CloudFoundry

Posted Apr 10, 2012
STS (as of version 2.8), by default, uses development environment when deploying a Grails application to server. Usually you would want to deploy your application in production mode instead to get the best performance.

To do this in STS, go to your project properties and navigate to Grails > Run On Server. Change the value from "dev" to "prod".



Hope this helps. My website has been deployed in Cloud Foundry for more more than a year and only now I've discovered that it's running in development mode!


Source:
http://forum.springsource.org/showthread.php?108405-Deploy-To-Cloud-Foundary-As-Prod&highlight=

Oct 13, 2011

Fixing Errors in STS when Moving Grails Projects

Posted Oct 13, 2011

Problem
Did you transfer or check out your projects to another computer and found out that your projects contains errors due to missing plugins? The error is something like:
Project is missing required source folder: '.link_to_grails_plugins/...

Solution
Right click on the Project -> Grails Tools -> Refresh Dependencies