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
6
votes
2 answers

Grails using grails var in GSP Site inside javascript

I have a question using grails variable values in javascript code in a GSP file. For Example: I have a session value session.getAttribute("selectedValue") and I want to use this value inside javascript code part. My solution is now (inside a…
grailsInvas0r
  • 655
  • 2
  • 10
  • 25
6
votes
1 answer

Grails form tag ID property for css

When you use grails form tag how can you have an id selector in the rendered HTML form tag? If you use it renders the form post URL as the…
Jon
  • 1,039
  • 2
  • 11
  • 16
6
votes
2 answers

using tag in grails

I am new to grails. I came across a set tag which we can use in gsp pages itself to set the values which is similar to setting model from the controller. so that when we write ${home} it outputs…
user5795168
6
votes
1 answer

println in grails gsp file

I know this is simple thing, but i was not aware. I used println in gsp file and expected to print output in console. But this is showing on page. <% for(int i =0; i < threads.size();i++) { println i } %> thanks.
Srinath
  • 1,293
  • 3
  • 16
  • 25
6
votes
4 answers

How to get current_user by using Spring Security Grails plugin in GSP

I am newbie in Grails. I am using Spring Security Grails plugin for Authentication purpose. I want to get current user in my view gsp file. I am trying like this ...
Free-Minded
  • 5,322
  • 6
  • 50
  • 93
6
votes
3 answers

how to debug a gsp page? (no grails, just gsp)

I've tried with netbeans and eclipse, with no luck... (coudn't try IntelliJ idea) I gave a quick look ant the code http://kickjava.com/src/groovy/servlet/TemplateServlet.java.htm and it gives me the impression that .gsp pages are translated to…
opensas
  • 60,462
  • 79
  • 252
  • 386
6
votes
5 answers

How to call a Grails service in a view?

Simple question : I have a service class (let's say helpersService) and a method def constructURI(params). How can I call this method from a template view. I have tried the following code without success <% def helpersService = new HelpersService()…
fabien7474
  • 16,300
  • 22
  • 96
  • 124
6
votes
3 answers

Error evaluating expression: Cannot invoke method getAt() on null object

I have a Question domain model designed as follows class Question { List choiceCollection; static hasMany = [choiceCollection:Choice] static mappping = { choiceCollection(joinTable:false) } } To fulfill my needs,…
Arthur Ronald
  • 33,349
  • 20
  • 110
  • 136
5
votes
3 answers

Using partial template under view root

I have a partial template I'm including in my main.gsp. This partial content will be slightly differnt for each controller/page on the site. Therefore I will have a seperate _headerDetails.gsp for each view directory. This works fine except for the…
Thomas Buckley
  • 5,836
  • 19
  • 62
  • 110
5
votes
1 answer

Grails - Custom tag inside a standard Grails tag

It is possible to call a Grails' tag inside another one using the following synthax.
Alexandre Bourlier
  • 3,972
  • 4
  • 44
  • 76
5
votes
5 answers

How to attemp sec:loggedInUserInfo into a variable in gsp

I want to get value of sec:loggedInUserInfo and attempt into a variable named user. My code looks like this: <% def user = *value of field loggedInUserInfo * %> Is it possible for doing that?
Mr Zoomzoom
  • 51
  • 1
  • 3
5
votes
2 answers

Grails - Set "disabled" attribute name and value in GSP

I´m trying to do this without success: I want to apply a disabled attribute, ONLY if the ${disabled} variable is TRUE. I don't want to use conditionals, because in other views I got a lot of code and…
David Morabito
  • 1,498
  • 1
  • 12
  • 22
5
votes
1 answer

Need to serve both GSPs and JSON from a Grails 3.1.5 app

I wanted my Grails 3.1.5 app to serve both JSON data using the *.gson format AND, for some pages/URLs I wanted to continue to use GSPs. I built an app using the rest-api profile. Then I copied over controllers and views from an other app that I'd…
Pankaj Tandon
  • 151
  • 1
  • 6
5
votes
1 answer

How do you nest g:each tags in gsp?

Assume I have the following classes class Genre { static hasMany=[author:Author] } class Author{ static hasMany=[books:Books] } class Books{ Author author } How do I go about printing this in the gsp using g:each tag?
Neoryder
  • 897
  • 2
  • 13
  • 26
5
votes
1 answer

How To Implement Adding An Extra Parameter in Grails Pagination?

I have a page/gsp that displays 3 different classes. This means that I need to add extra parameters to the pagination links. currently the link auto generated by default pagination tag in grails produces links like…
Neoryder
  • 897
  • 2
  • 13
  • 26