Questions tagged [gsp]

Groovy Server Pages (GSP) is a presentation language for web applications, similar to JSP. GSP allows static and dynamic content to be mixed in the same document. The result is a dynamically generated HTML, XML or other type of document in response to a Web client request.

Groovy Server Pages (GSP) is a view technology which can be used for designing web application using Grails Framework. Developing GSP are very much similar to that of designing web pages with Active Server Pages (ASP) and Java Server Pages (JSP) but coding is very much simpler and easier than both of them. Users are provided with facility of having static, dynamic as well as mix of both contents at a time in a single application.

The output can be dynamically rendered to different forms like : HTML, XML, text and any other format based on Web client request object.If you are beginner in learning groovy, please read Introduction to Groovy – Scripting Language.

Advantages of using GSP using Grails

  1. A GSP uses Groovy GString for evaluation of expression generally using ${….} but whereas in JSP EL expressions are used for the same purpose but they are restricted only to object navigation to overcome this disadvantage JSTL functions can to be written for creating static helper methods, registering them through a taglib descriptor, adding a taglib declaration and finally implementing them using the function.
  2. A developer has been provided with Logical and Iterative tags in GSP with safe navigation operator and Elvis operator which can be implemented easily to fetch the needed results according to their requirement. For example these operators can be implemented in this manner: Safe navigation operator :${book.pages?.no()}
  3. Elvis operator : ${totalpages ?: 100}
  4. A GSPhas ability for invoking methods through Grails dynamic tags which makes it easier to produce well-formed markup:
<!-- With a regular tag -->
<a href="<g:createLink action="list" />">Click here</a>
<!-- As a method call -->
<a href="${createLink(action:'list')}">Click here</a>
  1. Creating and testing custom tag libraries using GSP are very easier then JSP since there is no need for developer to code tld files and taglib declarations.
1323 questions
45
votes
6 answers

Overriding grails.views.default.codec='html' config back to 'none'

In Grails (<2.3), if I leave grails.views.default.code='none' in the grails Config.groovy, it's up to me to HTML encode my expressions explicitly in the GSP files: ${myValue?.encodeAsHTML()}. If I set grails.views.default.codec='html" in the…
John Flinchbaugh
  • 2,338
  • 1
  • 17
  • 20
41
votes
4 answers

What does the question mark mean in GSP/Grails?

I saw this in my generated GSP pages. What does the ? mean?
Amir Raminfar
  • 33,777
  • 7
  • 93
  • 123
40
votes
4 answers

Are there any good tutorials for using sitemesh in a grails application?

I'm a pretty experienced Grails developer, but most of my experience has been with using grails for serving up JSON/XML to a flex app and some relatively simple HTML websites. I've been diving deeper into using the sitemesh integration in grails and…
Ted Naleid
  • 26,511
  • 10
  • 70
  • 81
39
votes
3 answers

Render GSP view as compact html file

I have gsp view files wherein tags are formatted for readability with whitespaces. I am expected to remove those so that the rendered html file is compact. So, is there a way in grails using plugin or any other means that I can tell grails to remove…
Sumit Shrestha
  • 919
  • 2
  • 8
  • 20
30
votes
4 answers

How do I call a Grails service from a gsp?

How can I invoke a service directly from a view? I'm trying with ${my.domain.service.method}, but it complains it can't find the property. And no, I don't want to use a controller because the view is a template.
xain
  • 13,159
  • 17
  • 75
  • 119
30
votes
2 answers

Grails: Templates vs TagLibs.

In Grails, there are two mechanisms for modularity in the view layers: Template and TagLib. While I am writing my own Grails app, I am often facing the same question when I need to write an UI component: do I need to use a template or a TagLib?…
fabien7474
  • 16,300
  • 22
  • 96
  • 124
25
votes
7 answers

In a grails gsp template, how can I use a server side comment without sitemesh throwing an error?

When I use a standard jsp comment block in a gsp template <%-- some server-side comment --%> , sitemesh throws an 'unexpected token' error. Is there another comment syntax I can use?
gabe
  • 1,127
  • 1
  • 11
  • 23
21
votes
2 answers

Grails GSP tag set as integer?

Using Grails' GSP tag, is it possible to specify the type of the variable? I want to declare an integer variable, but always declares a sting. For example: ${x.getClass()} ${x+23} results in class…
Steve Kuo
  • 61,876
  • 75
  • 195
  • 257
17
votes
3 answers

Identifying ajax request or browser request in grails controller

I am developing a grails application which uses lot of ajax.If the request is ajax call then it should give response(this part is working), however if I type in the URL in the browser it should take me to the home/index page instead of the requested…
DonX
  • 16,093
  • 21
  • 75
  • 120
17
votes
3 answers

Defining default sort-order in Grails/GORM

Let's say I have definied a User object using GORM. Each user can have zero or more Login:s. Each Login has a timestamp. When retrieving user.logins I want the logins to be sorted based on the value of login.date. What is the correct Grails way to…
knorv
  • 49,059
  • 74
  • 210
  • 294
17
votes
5 answers

Where should I put javascript libraries in a Grails app?

I have a couple of Javascript libraries of my own that do some nice prettyfying of my HTML pages and I want to include them in my gsp pages, particularly the landing page of my app. I have tried putting them in views folder and web-app/js and…
Simon
  • 78,655
  • 25
  • 88
  • 118
16
votes
2 answers

GSP: check if model (variable) is empty not working

Im new to grails (1.3.7) and Im trying to get something to work: In my controller, I give back a few lists which I want to access in my gsp. Accessing works, but I only want to access them if they are not empty. The check if a list is empty or not…
nano7
  • 2,455
  • 7
  • 35
  • 52
13
votes
5 answers

Is it possible to work with GSP (groovy server pages) without the whole grails stuff?

I'd just like to play a little bit with groovy I was thinking about developing my own-tiny web framework, something very simple and manageable... So i'd like tou use GSP pages whtout having to install the whole grails stuff, with all its…
opensas
  • 60,462
  • 79
  • 252
  • 386
13
votes
4 answers

gsp parameter passing from controller

how can i pass parameters to a groovy server page via a controller that are not an instance of a domain class ?
SomeEUGuy
  • 187
  • 1
  • 1
  • 7
13
votes
1 answer

Grails Render Template Different Controller/Path

I have a template that exists under views/dashboard/_myTemplate.gsp and from the DashboardController I can simply call render template:'myTemplate' and all is well. I have a need to render this template from a different controller but the render…
Gregg
  • 34,973
  • 19
  • 109
  • 214
1
2 3
88 89