File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Groovy and the fly likes how to get request parameters in grails Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "how to get request parameters in grails" Watch "how to get request parameters in grails" New topic
Author

how to get request parameters in grails

Sabarish Venkat
Ranch Hand

Joined: Jan 18, 2012
Posts: 136

Usually in jsp we will use request.getParameter() function to get the parameter values from prevoius page. Like that how we can get the value in grails do we have any functions to get a parameter value from gsp page to a controller.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Grails provides a wrapper around the HttpServletRequest and it is injected automatically into every controller with a variable named params. So if you had the following:

Once submitted, you would access username in your controller like so:


GenRocket - Experts at Building Test Data
Sabarish Venkat
Ranch Hand

Joined: Jan 18, 2012
Posts: 136

Thats fine but when i want to use that variable across my pages wherever i wish how i take the value i want to pass that params to the gsp or to the model class
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Every view in Grails is accessed via a Controller. If you want to pass data from the controller to your GSP you would do something like the following:



That would, by convention, render a show.gsp and pass userInstance into the GSP. You should really spend some time in the documentation. It is quite verbose on this topic.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Sabarish Venkat,
Your post was moved to a new topic.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to get request parameters in grails