The below variables have precedence over normal seam context resolution. In other words a variable will
be resolved to a seam context as long as it does not clash with one of the below mentioned variables.
Variables available for view scripts and librariesName | Type | Description |
---|
servlet | interface javax.servlet.ServletContext | The current servlet context |
faces | class javax.faces.context.FacesContext | The current faces context |
el | class javax.el.ELResolver | The current Expression Language resolver |
ef | class javax.el.ExpressionFactory | The current Expression Factory |
elCtx | class javax.el.ELContext | The current Expression Language context |
viewId | class java.lang.String | The view id of the current view |
path | class java.lang.String | The current file system path corresponding to the current view |
parentPath | class gracelets.util.FileWalker | An easy navigational object for getting relative files to the current view |
servletRoot | class gracelets.util.FileWalker | An easy navigational object for getting relative files to the servlet context |
actionURL | class java.lang.String | The url corresponding to the current view used for example with forms or links for post backs |
external | class javax.faces.context.ExternalContext | The current JSF external context |
request | class java.lang.Object | The current request object (an instanceof HttpServletRequest for http requests) |
response | class java.lang.Object | The current response object (an instanceof HttpServletResponse for http responses) |
param | interface java.util.Map | The current map that holds the posted variables for this request |
paramNames | interface java.util.Collection | A collection holding the names of the posted variables for this request |
varCtx | interface java.util.Map | Used to resolve context variables that have name clashes with local variables |
headers | interface java.util.Map | A header name -> collection map. Generally each collection will only contain one value. |
cookies | interface java.util.Map | A cookie name -> Cookie object map. |
useragent | class java.lang.String | A simple convenience method allowing one to be able to quickly evaluate the user agent. |
*Context | interface gracelets.api.context.VariableContext | Any variable that starts with the name of a scope in the current setup and ends with Context will give direct access to that scope |
Variable:
servlet
(See also:
Javadoc page)
For example, to get the file system root of your web application you can do the following:
Variable:
faces
(See also:
Javadoc page)
To force the current view to be rendered, you could do the following:
Variable:
el
(See also:
Javadoc page)
To force el resolution on an object you could call the following:
Variable:
ef
(See also:
Javadoc page)
To create a value expression object you could call the following:
Variable:
elCtx
(See also:
Javadoc page)
To get the current variable mapper:
Variable:
viewId
This can be helpful for debugging or other purposes where you need to know what the view id is:
Variable:
path
This can be helpful when needing information about the file system location of the current view:
Variable:
parentPath
If you need to access files based off where your current view is located, this can be helpful. For instance
if you wanted to access some xml file next to the view you could do this:
Variable:
servletRoot
If you need to access files based off where your web application is located, this can be helpful. For instance
if you wanted to access some xml off a certain directory in your web app:
Variable:
actionURL
When you need to post back and maybe want to write your own forms you can easily get the post back url with this variable
(this can be especially helpful when writing library components, in particular form renderers):
Variable:
external
(See also:
Javadoc page)
If you don't want to deal directly with the servlet implementation, you can use the faces external context object
available via this variable. For example, you could get remote user info by using the following:
Variable:
request
This can be used to access the servlet request object directly (the same as external.request). For example, to get the
request headers you could do this:
Variable:
response
This can be used to access the servlet response object directly (the same as external.response). For example, to add a response header
you could do this:
Variable:
param
This can be used to access posted variables for the current request. On some pages you may prefer to use only use get's
together with passed parameters, maybe to show some document, you could do this:
Variable:
paramNames
This can be used to access posted variables names for the current request. To loop through the posted variable names you could do the following:
Variable:
varCtx
When a local variable interferes with something in the variable context, or even if one of the above variables does, you can
force variable context resolution by using this variable. The following would assign the context variable 'myLocalVar' to the value
variable instead of getting the local variable:
Variable:
headers
You can easily debug the request headers with this variable:
Toggle Line Numbers |
1
2
headers.each { header -> 3
println "Header: $header.key" 4
header.value.each { println "Value: $it" } 5
} 6
|
Variable:
cookies
You can easily check for the existence of a cookie with this variable:
Toggle Line Numbers |
1
2
if (!cookies.myCompanyCookie) { 3
response.addCookie("myCompanyCookie", "someValue") 4
} 5
|
Variable:
useragent
You can check/anaylize the User-Agent (browser) by simply referencing this variable:
Variable:
*Context
You can force access to set/get a variable in a particular scope. The available scopes depend on the framework you are using (etc, Seam, Spring). Gracelets
comes with a set of default scopes (view, request, conversation (default), session, application) that you can use. So for instance if you wanted to hold state in
a variable in the current view context, you could make sure it is stored in that scope by doing the following: