Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion grails-doc/src/en/ref/Servlet API/servletContext.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ under the License.
=== Purpose


The servletContext object is an instance of the Servlet API's {jakartaee}jakarta/servlet/ServletContext.html[ServletContext] class.
The `servletContext` object is an instance of the Servlet API's {jakartaee}jakarta/servlet/ServletContext.html[ServletContext] class.


=== Examples
Expand Down
13 changes: 9 additions & 4 deletions grails-doc/src/en/ref/Tag Libraries/actionName.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,20 @@ Returns the name of the currently executing action

[source,groovy]
----
class BookController {
def list() {
log.info "Executing action $actionName"
class ExamplesTagLib {

render(view: actionName)
def showActionName = { attrs, body ->
out << "Executing action: ${actionName}"
}

}
----

[source,xml]
----
<g:showActionName />
----


=== Description

Expand Down
14 changes: 9 additions & 5 deletions grails-doc/src/en/ref/Tag Libraries/controllerName.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@ Returns the name of the currently executing controller

[source,groovy]
----
class BookController {
class ExamplesTagLib {

def list() {
log.info "Executing within controller $controllerName"

render(view: actionName)
def showControllerName = { attrs, body ->
out << "Executing controller: ${controllerName}"
}

}
----

[source,xml]
----
<g:showControllerName />
----


=== Description

Expand Down
11 changes: 7 additions & 4 deletions grails-doc/src/en/ref/Tag Libraries/flash.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,20 @@ A temporary storage map that stores objects within the session for the next requ

[source,groovy]
----
class BookController {
class ExamplesTagLib {

def index() {
def message = {
flash.message = "Welcome!"
redirect(action: 'home')
out << "Flash: ${flash}"
}

def home() {}
}
----

[source,xml]
----
<g:showRequest /> // Outputs "Flash: [message:Welcome!]"
----

=== Description

Expand Down
3 changes: 2 additions & 1 deletion grails-doc/src/en/ref/Tag Libraries/pageScope.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ A reference to the binding of the GSP that the tag library is being executed wit

[source,groovy]
----
class BookTagLib {
class ExamplesTagLib {

def parent = { attrs, body ->
pageScope.parent = "John"
Expand All @@ -43,6 +43,7 @@ class BookTagLib {
def child = { attrs, body ->
out << "My parent is ${pageScope.parent}"
}

}
----

Expand Down
26 changes: 8 additions & 18 deletions grails-doc/src/en/ref/Tag Libraries/params.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,18 @@ A mutable multi-dimensional map (hash) of request (CGI) parameters.
To obtain a request parameter called `id`:
[source,groovy]
----
class BookController {
def show() {
def book = Book.get(params.id)
class ExamplesTagLib {

def showParameter = {
out << "Parameter id has the value ${params['id']}"
}

}
----

To perform data binding (see link:{guidePath}theWebLayer.html#dataBinding[data binding] in the user guide):

[source,groovy]
[source,xml]
----
def save() {
def book = new Book(params) // bind request parameters onto properties of book
}
<g:showParameter />
----


Expand All @@ -59,16 +57,8 @@ The standard Servlet API provides access to parameters with the `HttpServletRequ
The `params` object can be indexed into using the array index operator or de-reference operator, so given the URL `/hello?foo=bar` you can access `foo` with

----
println params.foo
params['id']
----

The params object can also be used to bind request parameters onto the properties of a domain class using either the constructor or the link:{domainClassesRefFromRef}properties.html[properties] property:

[source,groovy]
----
def book = new Book(params)
book = Book.get(1)
book.properties = params
----

For further reading see link:{guidePath}theWebLayer.html#dataBinding[data binding] in the user guide.
16 changes: 10 additions & 6 deletions grails-doc/src/en/ref/Tag Libraries/request.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,31 @@ under the License.
=== Purpose


The link:{servletApiRefFromRef}request.html[request] object is an instance of the Servlet API's {javaee}javax/servlet/http/HttpServletRequest.html[HttpServletRequest] class
The link:{servletApiRefFromRef}request.html[request] object is an instance of the Servlet API's {jakartaee}jakarta/servlet/http/HttpServletRequest.html[HttpServletRequest] class


=== Examples


[source,groovy]
----
class BookController {
def list() {
log.info "User agent: ${request.getHeader("User-Agent")}"
class ExamplesTagLib {

render(view: actionName)
def showRequest = { attrs, body ->
out << "Request ${request.getHeader('User-Agent')}"
}

}
----

[source,xml]
----
<g:showRequest />
----

=== Description


The {javaee}javax/servlet/http/HttpServletRequest.html[HttpServletRequest] class is useful for, amongst other things, obtaining request headers, storing request scoped attributes and establishing information about the client. Refer to the Servlet API's javadocs for further information.
The {jakartaee}jakarta/servlet/http/HttpServletRequest.html[HttpServletRequest] class is useful for, amongst other things, obtaining request headers, storing request scoped attributes and establishing information about the client. Refer to the Servlet API's javadocs for further information.

NOTE: The additional methods added to the link:{servletApiRefFromRef}request.html[request] object are documented in the Grails Servlet API reference guide
13 changes: 7 additions & 6 deletions grails-doc/src/en/ref/Tag Libraries/response.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,27 @@ under the License.
=== Purpose


The {grailsdocs}ref/Servlet%20API/response.html[response] object is an instance of the Servlet API's {javaee}javax/servlet/http/HttpServletResponse.html[HttpServletResponse] class
The link:{servletApiRefFromRef}response.html[response] object is an instance of the Servlet API's {jakartaee}jakarta/servlet/http/HttpServletResponse.html[HttpServletResponse] class


=== Examples


[source,groovy]
----
class BookController {
def downloadFile() {
byte[] bytes = // read bytes
response.outputStream << bytes
class ExamplesTagLib {

def setHeader = {
response.setHeader('Content-Type', 'text/html; charset=utf-8')
}

}
----


=== Description


The Servlet API's `HttpServletResponse` class can be used within Grails to perform all typical activities such as writing out binary data, writing directly to the response and sending error response codes to name but a few. Refer to the documentation on the {javaee}javax/servlet/http/HttpServletResponse.html[HttpServletResponse] class in the Servlet API for more information.
The Servlet API's `HttpServletResponse` class can be used within Grails to perform all typical activities such as writing out binary data, writing directly to the response and sending error response codes to name but a few. Refer to the documentation on the {jakartaee}jakarta/servlet/http/HttpServletResponse.html[HttpServletResponse] class in the Servlet API for more information.

NOTE: The additional methods added to the link:{servletApiRefFromRef}response.html[response] object are documented in the Grails Servlet API reference guide
20 changes: 7 additions & 13 deletions grails-doc/src/en/ref/Tag Libraries/servletContext.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,27 @@ under the License.
=== Purpose


The link:{servletApiRefFromRef}servletContext.html[servletContext] object is an instance of the Servlet API's {javaee}javax/servlet/ServletContext.html[ServletContext] class.
The link:{servletApiRefFromRef}servletContext.html[servletContext] object is an instance of the Servlet API's {jakartaee}jakarta/servlet/ServletContext.html[ServletContext] class.


=== Examples


[source,groovy]
----
class BookController {
def doSomething() {
def input
try {
input = servletContext.getResourceAsStream("/WEB-INF/myscript.groovy")
def result = new GroovyShell().evaluate(input.text)
render result
}
finally {
input.close()
}
class ExamplesTagLib {

def doSomething = {
out << "Servlet major version: ${servletContext.majorVersion }"
}

}
----


=== Description


The Servlet API's {javaee}javax/servlet/ServletContext.html[ServletContext] is useful for, amongst other things, storing global application attributes, reading local server resources and establishing information about the servlet container.
The Servlet API's {jakartaee}jakarta/servlet/ServletContext.html[ServletContext] is useful for, amongst other things, storing global application attributes, reading local server resources and establishing information about the servlet container.

NOTE: Grails adds additional methods to the standard Servlet API's link:{servletApiRefFromRef}servletContext.html[servletContext] object. See link for details.
10 changes: 4 additions & 6 deletions grails-doc/src/en/ref/Tag Libraries/session.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,28 @@ under the License.
=== Purpose


The {grailsdocs}ref/Servlet%20API/session.html[session] object is an instance of the Servlet API's {javaee}javax/servlet/http/HttpSession.html[HttpSession] class
The link:{servletApiRefFromRef}session.html[session] object is an instance of the Servlet API's {jakartaee}jakarta/servlet/http/HttpSession.html[HttpSession] class


=== Examples


[source,groovy]
----
class UserController {
class ExampleTagLib {

def logout() {
def logout = {
log.info "User agent: " + request.getHeader("User-Agent")
session.invalidate()
redirect(action: "login")
}

def login() {}
}
----


=== Description


The {javaee}javax/servlet/http/HttpSession.html[HttpSession] class is useful for associated session data with a client.
The {jakartaee}jakarta/servlet/http/HttpSession.html[HttpSession] class is useful for associated session data with a client.

NOTE: The additional methods added to the link:{servletApiRefFromRef}session.html[session] object are documented in the Grails Servlet API reference guide
Loading