All Packages Class Hierarchy This Package Previous Next Index
Class org.webmacro.servlet.WebContext
java.lang.Object
|
+----org.webmacro.util.java2.HashMap
|
+----org.webmacro.servlet.WebContext
- public final class WebContext
- extends HashMap
A WebContext is the point of intersection between the back-end
Java code and the template script. Programmers are expected to
place objects needed by the template into the WebContext hashtable,
whereupon they become available in the template as a variable, with
the same name as their key in the hashtable.
At the simplest level, this means you can create variables by
adding them as strings: put("Title","Product Listings") creates
a variable in the template called $Title which evaluates to
the string "Product Listings".
You can also put complex, bean-like, objects into the context
and rely on WebMacro's property introspection to analyze your
object and determine what sub-variables it can extract from
the object you deposit.
For example, if you put a Customer object into the WebContext
under the key "Buyer", then that creates a $Buyer variable
in the template script. The template can then use methods
on the Customer class via the introspector. So, $Buyer.Name
might be translated into Customer.getName(). See the
PropertyOperator class for an explanation of the kinds of
introspection that WebMacro will performed.
A majority of the methods of this class are intended as
conveniences for the template writer. The getForm(String) method,
for example, creates a $Form variable in the template which
can be used to access Form data: $Form.id translates into a
call to WebContext.getForm("id").
It also contains a variety of properties populated with information
about the current request, such as the session data,
the cookies, and other information.
Please note that if you put values into the hashtable that have
the same name as properties already declared here then your values
will be hidden from the WebMacro script language--Property
introspection will find the properties before checking the hashtable.
If you absolutely must use the same names as the WebContext
a workaround is to declare your own hashtable and
put them into that. Then put your hashtable into the context.
If your hashtable were called "data" and you had an object
called "http" stuck in it, you could then access that as
"$data.http" from the WebMacro script language.
If you want to use Property introspection from the Java side of
things, you can do that using the getProperty method. This might
be convenient if you want to access things under exactly the same
name in Java as you do in the WebMacro script language.
- See Also:
- Reactor, Property, Map
-
getBroker()
- This object provides access to extended services and other
resources, which live in the org.webmacro.resource package,
or that you define, or obtain from a third party.
-
getCGI()
- This object provides information from the request header, but
does so under the standard CGI names.
-
getConfig(String)
- This object contains configuration data about the WebMacro
system, based on a file loaded at startup time.
-
getCookie(String)
- Search the cookie jar in the request and see if it contains the
requested cookie; if so return it.
-
getForm(String)
- This is a shortcut for HttpRequest.getParameterValues(field)[0]
you can thus use $Form.paramName as a variable in a WebMacro
property, which will return the first value associated with that
field name.
-
getFormList(String)
- This is a shortcut for HttpRequest.getParameterValues(field)
you can thus use $Form.paramName as a variable in a WebMacro
property, which will return an array.
-
getRequest()
- The HttpServletRequest object which contains information
provided by the HttpServlet superclass about the Request.
-
getResponse()
- The HttpServletResponse object which contains information
about the response we are going to send back.
-
getSession()
- Get an HttpSession object associated with the current session.
-
getUsers()
- This object contains information about users in the WebMacro
system.
-
setCookie(String, String)
- Create a new cookie with the supplied name and value and set it
in the response header.
getRequest
public final HttpServletRequest getRequest()
- The HttpServletRequest object which contains information
provided by the HttpServlet superclass about the Request.
Much of this data is provided in other forms later on;
those interfaces get their data from this object.
In particular the form data has already been parsed.
- See Also:
- HttpServletRequest, Property
getResponse
public final HttpServletResponse getResponse()
- The HttpServletResponse object which contains information
about the response we are going to send back. Many of these
services are provided through other interfaces here as well;
they are built on top of this object.
- See Also:
- HttpServletResponse, Property
getSession
public final HttpSession getSession()
- Get an HttpSession object associated with the current session.
In this version this is the HttpSession returned by the JSDK, but
future versions of WebMacro may turn out to be smarter than the
JSDK in tracking users, and therefore you should prefer to use
this getSession method rather than getRequest().getSession(true),
which for now is equivalent.
getForm
public final String getForm(String field)
- This is a shortcut for HttpRequest.getParameterValues(field)[0]
you can thus use $Form.paramName as a variable in a WebMacro
property, which will return the first value associated with that
field name.
getFormList
public final String[] getFormList(String field)
- This is a shortcut for HttpRequest.getParameterValues(field)
you can thus use $Form.paramName as a variable in a WebMacro
property, which will return an array.
getConfig
public final String getConfig(String key)
- This object contains configuration data about the WebMacro
system, based on a file loaded at startup time.
- See Also:
- Property, Config
getUsers
public final ResourceMap getUsers()
- This object contains information about users in the WebMacro
system.
getCGI
public final CGI_Impersonator getCGI()
- This object provides information from the request header, but
does so under the standard CGI names. The names in request are
actually already pretty close to that--the real motivation for
having this object is to make the CGI names work in the
WebMacro script language, which uses introspection. Via
introspection getAUTH_TYPE is available as just "AUTH_TYPE",
which is identical to its name in CGI.
Many people may be more comfortable with the CGI names.
- See Also:
- Property
getCookie
public final Cookie getCookie(String cookieName)
- Search the cookie jar in the request and see if it contains the
requested cookie; if so return it.
setCookie
public final void setCookie(String name,
String value)
- Create a new cookie with the supplied name and value and set it
in the response header.
getBroker
public final ResourceBroker getBroker()
- This object provides access to extended services and other
resources, which live in the org.webmacro.resource package,
or that you define, or obtain from a third party.
All Packages Class Hierarchy This Package Previous Next Index