You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/docs/guide/GSPBasics.adoc
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@ In the next view sections we'll go through the basics of GSP and what is availab
2
2
3
3
GSP supports the usage of `<% %>` scriptlet blocks to embed Groovy code (again this is discouraged):
4
4
5
-
[source,xml]
5
+
[,xml]
6
6
----
7
7
<html>
8
8
<body>
@@ -13,7 +13,7 @@ GSP supports the usage of `<% %>` scriptlet blocks to embed Groovy code (again t
13
13
14
14
You can also use the `<%= %>` syntax to output values:
15
15
16
-
[source,xml]
16
+
[,xml]
17
17
----
18
18
<html>
19
19
<body>
@@ -24,7 +24,7 @@ You can also use the `<%= %>` syntax to output values:
24
24
25
25
GSP also supports JSP-style server-side comments (which are not rendered in the HTML response) as the following example demonstrates:
26
26
27
-
[source,xml]
27
+
[,xml]
28
28
----
29
29
<html>
30
30
<body>
@@ -34,4 +34,4 @@ GSP also supports JSP-style server-side comments (which are not rendered in the
34
34
</html>
35
35
----
36
36
37
-
WARNING: Embedding data received from user input has the risk of making your application vulnerable to an Cross Site Scripting (XSS) attack. Please read the documentation on link:security.html#xssPrevention[XSS prevention] for information on how to prevent XSS attacks.
37
+
WARNING: Embedding data received from user input has the risk of making your application vulnerable to an Cross Site Scripting (XSS) attack. Please read the documentation on {grailsdocs}guide/security.html#xssPrevention[XSS prevention] for information on how to prevent XSS attacks.
Copy file name to clipboardExpand all lines: src/main/docs/guide/GSPBasics/expressions.adoc
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,4 +11,4 @@ In GSP the `<%= %>` syntax introduced earlier is rarely used due to the support
11
11
12
12
However, unlike JSP EL you can have any Groovy expression within the `${..}` block.
13
13
14
-
WARNING: Embedding data received from user input has the risk of making your application vulnerable to an Cross Site Scripting (XSS) attack. Please read the documentation on link:security.html#xssPrevention[XSS prevention] for information on how to prevent XSS attacks.
14
+
WARNING: Embedding data received from user input has the risk of making your application vulnerable to a Cross Site Scripting (XSS) attack. Please read the documentation on {grailsdocs}guide/security.html#xssPrevention[XSS prevention] for information on how to prevent XSS attacks.
Within the `<% %>` brackets you can declare variables:
2
2
3
-
[source,xml]
3
+
[,]
4
4
----
5
5
<% now = new Date() %>
6
6
----
7
7
8
8
and then access those variables later in the page:
9
9
10
-
[source,xml]
10
+
[,]
11
11
----
12
12
<%=now%>
13
13
----
14
14
15
15
Within the scope of a GSP there are a number of pre-defined variables, including:
16
16
17
-
* `application` - The http://docs.oracle.com/javaee/1.4/api/javax/servlet/ServletContext.html[javax.servlet.ServletContext] instance
18
-
* `applicationContext` The Spring http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/ApplicationContext.html[ApplicationContext] instance
19
-
* `flash` - The link:{controllersRef}/flash.html[flash] object
20
-
* `grailsApplication` - The http://docs.grails.org/latest/api/grails/core/GrailsApplication.html[GrailsApplication] instance
17
+
* `application` - The {javaee}javax/servlet/ServletContext.html[javax.servlet.ServletContext] instance
18
+
* `applicationContext` The Spring {springapi}org/springframework/context/ApplicationContext.html[ApplicationContext] instance
19
+
* `flash` - The {controllersRef}/flash.html[flash] object
20
+
* `grailsApplication` - The {grailsapi}grails/core/GrailsApplication.html[GrailsApplication] instance
21
21
* `out` - The response writer for writing to the output stream
22
-
* `params` - The link:{controllersRef}/params.html[params] object for retrieving request parameters
23
-
* `request` - The http://docs.oracle.com/javaee/1.4/api/javax/servlet/http/HttpServletRequest.html[HttpServletRequest] instance
24
-
* `response` - The http://docs.oracle.com/javaee/1.4/api/javax/servlet/http/HttpServletResponse.html[HttpServletResponse] instance
25
-
* `session` - The http://docs.oracle.com/javaee/1.4/api/javax/servlet/http/HttpSession.html[HttpSession] instance
26
-
* `webRequest` - The http://docs.grails.org/latest/api/org/grails/web/servlet/mvc/GrailsWebRequest.html[GrailsWebRequest] instance
22
+
* `params` - The {controllersRef}/params.html[params] object for retrieving request parameters
23
+
* `request` - The {javaee}javax/servlet/http/HttpServletRequest.html[HttpServletRequest] instance
24
+
* `response` - The {javaee}javax/servlet/http/HttpServletResponse.html[HttpServletResponse] instance
25
+
* `session` - The {javaee}javax/servlet/http/HttpSession.html[HttpSession] instance
26
+
* `webRequest` - The {grailsapi}org/grails/web/servlet/mvc/GrailsWebRequest.html[GrailsWebRequest] instance
Copy file name to clipboardExpand all lines: src/main/docs/guide/introduction.adoc
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,22 +6,22 @@ GSP was previously part of Grails core, but since version 3.3 it is an independe
6
6
.build.gradle
7
7
----
8
8
dependencies {
9
-
...
9
+
//...
10
10
implementation "org.grails.plugins:gsp:{version}"
11
11
}
12
12
----
13
13
14
-
In addition for production compilation you should apply the `grails-gsp` Gradle plugin:
14
+
In addition, for production compilation you should apply the `grails-gsp` Gradle plugin:
15
15
16
-
[source,groovy,subs="attributes"]
16
+
[source,groovy]
17
17
.build.gradle
18
18
----
19
-
apply plugin:"org.grails.grails-gsp"
19
+
apply plugin:"org.grails.grails-gsp"
20
20
----
21
21
22
-
GSPs themselves live in the `grails-app/views` directory and are typically rendered automatically (by convention) or with the link:{controllersRef}/render.html[render] method such as:
22
+
GSPs themselves live in the `grails-app/views` directory and are typically rendered automatically (by convention) or with the {controllersRef}/render.html[render] method such as:
23
23
24
-
[source,java]
24
+
[source,groovy]
25
25
----
26
26
render(view: "index")
27
27
----
@@ -32,7 +32,7 @@ NOTE: Although it is possible to have Groovy logic embedded in your GSP and doin
32
32
33
33
A GSP typically has a "model" which is a set of variables that are used for view rendering. The model is passed to the GSP view from a controller. For example consider the following controller action:
34
34
35
-
[source,java]
35
+
[source,groovy]
36
36
----
37
37
def show() {
38
38
[book: Book.get(params.id)]
@@ -41,9 +41,9 @@ def show() {
41
41
42
42
This action will look up a `Book` instance and create a model that contains a key called `book`. This key can then be referenced within the GSP view using the name `book`:
43
43
44
-
[source,groovy]
44
+
[source,gsp]
45
45
----
46
46
${book.title}
47
47
----
48
48
49
-
WARNING: Embedding data received from user input has the risk of making your application vulnerable to an Cross Site Scripting (XSS) attack. Please read the documentation on link:https://docs.grails.org/latest/guide/security.html#xssPrevention[XSS prevention] for information on how to prevent XSS attacks.
49
+
WARNING: Embedding data received from user input has the risk of making your application vulnerable to a Cross Site Scripting (XSS) attack. Please read the documentation on {grailsdocs}guide/security.html#xssPrevention[XSS prevention] for information on how to prevent XSS attacks.
Copy file name to clipboardExpand all lines: src/main/docs/guide/layouts.adoc
+26-25Lines changed: 26 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
==== Creating Layouts
3
3
4
4
5
-
Grails leverages http://sitemesh.org[Sitemesh], a decorator engine, to support view layouts. Layouts are located in the `grails-app/views/layouts` directory. A typical layout can be seen below:
5
+
Grails leverages https://github.com/sitemesh[Sitemesh], a decorator engine, to support view layouts. Layouts are located in the `grails-app/views/layouts` directory. A typical layout can be seen below:
6
6
7
7
[source,xml]
8
8
----
@@ -20,13 +20,13 @@ Grails leverages http://sitemesh.org[Sitemesh], a decorator engine, to support v
20
20
</html>
21
21
----
22
22
23
-
The key elements are the link:../ref/Tags/layoutHead.html[layoutHead], link:../ref/Tags/layoutTitle.html[layoutTitle] and link:../ref/Tags/layoutBody.html[layoutBody] tag invocations:
23
+
The key elements are the xref:../ref/Tags/layoutHead.adoc[layoutHead], xref:../ref/Tags/layoutTitle.adoc[layoutTitle] and xref:../ref/Tags/layoutBody.adoc[layoutBody] tag invocations:
24
24
25
25
* `layoutTitle` - outputs the target page's title
26
26
* `layoutHead` - outputs the target page's head tag contents
27
27
* `layoutBody` - outputs the target page's body tag contents
28
28
29
-
The previous example also demonstrates the link:../ref/Tags/pageProperty.html[pageProperty] tag which can be used to inspect and return aspects of the target page.
29
+
The previous example also demonstrates the xref:../ref/Tags/pageProperty.adoc[pageProperty] tag which can be used to inspect and return aspects of the target page.
30
30
31
31
32
32
==== Triggering Layouts
@@ -45,7 +45,7 @@ There are a few ways to trigger a layout. The simplest is to add a meta tag to t
45
45
</html>
46
46
----
47
47
48
-
In this case a layout called `grails-app/views/layouts/main.gsp` will be used to layout the page. If we were to use the layout from the previous section the output would resemble this:
48
+
In this case a layout called `grails-app/views/layouts/main.gsp` will be used to lay out the page. If we were to use the layout from the previous section the output would resemble this:
49
49
50
50
[source,xml]
51
51
----
@@ -68,23 +68,23 @@ In this case a layout called `grails-app/views/layouts/main.gsp` will be used to
68
68
69
69
Another way to specify a layout is to specify the name of the layout by assigning a value to the "layout" property in a controller. For example, if you have a controller such as:
70
70
71
-
[source,java]
71
+
[source,groovy]
72
72
----
73
73
class BookController {
74
74
static layout = 'customer'
75
75
76
-
def list() { ... }
76
+
def list() { /*...*/ }
77
77
}
78
78
----
79
79
80
-
You can create a layout called `grails-app/views/layouts/customer.gsp` which will be applied to all views that the `BookController` delegates to. The value of the "layout" property may contain a directory structure relative to the `grails-app/views/layouts/` directory. For example:
80
+
You can create a layout called `grails-app/views/layouts/customer.gsp` which will be applied to all views that the `BookController` delegates to. The value of the `layout` property may contain a directory structure relative to the `grails-app/views/layouts/` directory. For example:
81
81
82
-
[source,java]
82
+
[source,groovy]
83
83
----
84
84
class BookController {
85
85
static layout = 'custom/customer'
86
86
87
-
def list() { ... }
87
+
def list() { /*...*/ }
88
88
}
89
89
----
90
90
@@ -96,26 +96,27 @@ Views rendered from that controller would be decorated with the `grails-app/view
96
96
97
97
Another way to associate layouts is to use "layout by convention". For example, if you have this controller:
98
98
99
-
[source,java]
99
+
[source,groovy]
100
100
----
101
101
class BookController {
102
-
def list() { ... }
102
+
def list() { /*...*/ }
103
103
}
104
104
----
105
105
106
106
You can create a layout called `grails-app/views/layouts/book.gsp`, which will be applied to all views that the `BookController` delegates to.
107
107
108
108
Alternatively, you can create a layout called `grails-app/views/layouts/book/list.gsp` which will only be applied to the `list` action within the `BookController`.
109
109
110
-
If you have both the abovementioned layouts in place the layout specific to the action will take precedence when the list action is executed.
110
+
If you have both the above-mentioned layouts in place the layout specific to the action will take precedence when the list action is executed.
111
111
112
-
If a layout may not be located using any of those conventions, the convention of last resort is to look for the application default layout which
113
-
is `grails-app/views/layouts/application.gsp`. The name of the application default layout may be changed by defining a property
114
-
in `grails-app/conf/application.groovy` as follows:
112
+
If a layout is not located using any of those conventions, the convention of last resort is to look for the application default layout which
113
+
is `grails-app/views/layouts/application.gsp`. The name of the application default layout may be changed by defining the property `grails.sitemesh.default.layout`
114
+
in the application configuration as follows:
115
115
116
-
[source,java]
116
+
[source,yaml]
117
+
.grails-app/conf/application.yml
117
118
----
118
-
grails.sitemesh.default.layout = 'myLayoutName'
119
+
grails.sitemesh.default.layout: myLayoutName
119
120
----
120
121
121
122
With that property in place, the application default layout will be `grails-app/views/layouts/myLayoutName.gsp`.
@@ -124,15 +125,15 @@ With that property in place, the application default layout will be `grails-app/
124
125
==== Inline Layouts
125
126
126
127
127
-
Grails' also supports Sitemesh's concept of inline layouts with the link:../ref/Tags/applyLayout.html[applyLayout] tag. This can be used to apply a layout to a template, URL or arbitrary section of content. This lets you even further modularize your view structure by "decorating" your template includes.
128
+
Grails' also supports Sitemesh's concept of inline layouts with the xref:../ref/Tags/applyLayout.adoc[applyLayout] tag. This can be used to apply a layout to a template, URL or arbitrary section of content. This lets you even further modularize your view structure by "decorating" your template includes.
@@ -143,14 +144,14 @@ The content to apply a layout to
143
144
==== Server-Side Includes
144
145
145
146
146
-
While the link:../ref/Tags/applyLayout.html[applyLayout] tag is useful for applying layouts to external content, if you simply want to include external content in the current page you use the link:../ref/Tags/include.html[include] tag:
147
+
While the xref:../ref/Tags/applyLayout.adoc[applyLayout] tag is useful for applying layouts to external content, if you simply want to include external content in the current page you use the xref:../ref/Tags/include.adoc[include] tag:
147
148
148
149
[source,xml]
149
150
----
150
151
<g:include controller="book" action="list" />
151
152
----
152
153
153
-
You can even combine the link:../ref/Tags/include.html[include] tag and the link:../ref/Tags/applyLayout.html[applyLayout] tag for added flexibility:
154
+
You can even combine the xref:../ref/Tags/include.adoc[include] tag and the xref:../ref/Tags/applyLayout.adoc[applyLayout] tag for added flexibility:
154
155
155
156
[source,xml]
156
157
----
@@ -159,11 +160,11 @@ You can even combine the link:../ref/Tags/include.html[include] tag and the link
159
160
</g:applyLayout>
160
161
----
161
162
162
-
Finally, you can also call the link:../ref/Tags/include.html[include] tag from a controller or tag library as a method:
163
+
Finally, you can also call the xref:../ref/Tags/include.adoc[include] tag from a controller or tag library as a method:
0 commit comments