Class Context
- Since:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanstatic final doublestatic final floatstatic final intstatic final longstatic final intStatus code (403) indicating the server understood the request but refused to fulfill it.static final intStatus code (500) indicating an error inside the HTTP server which prevented it from fulfilling the request.static final intStatus code (304) indicating that a conditional GET operation found that the resource was available and not modified. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCookie(CookieBuilder builder) Adds theCookiecreated by aCookieBuilderto the response.voidaddDateHeader(String name, long date) Adds a response header with the given name and date-value.voidAdds a response header with the given name and integer value.voidAdds a response header with the given name and value.Returns the value of the named attribute.Returns a list of attribute names available to this request.body()Retrieves the body of this context's request as a string.byte[]Retrieves the body of this context's request as a byte array.Returns the name of the character encoding used in the body of this request.voidClears the text buffer is it's enabled.Returns the MIME type of the body of the request, or null if the type is not known.Returns the portion of the request URI that indicates the context of the request.Returns the unique identifier of the current continuation.booleancookieBoolean(String name) Retrieves the value of a named cookie and converts it to a boolean.booleancookieBoolean(String name, boolean defaultValue) Retrieves the value of a named cookie and converts it to a boolean, using a default value if no input value is present.doublecookieDouble(String name) Retrieves the value of a named cookie and converts it to a double.doublecookieDouble(String name, double defaultValue) Retrieves the value of a named cookie and converts it to a double, using a default value if no input value is present.floatcookieFloat(String name) Retrieves the value of a named cookie and converts it to a float.floatcookieFloat(String name, float defaultValue) Retrieves the value of a named cookie and converts it to a float, using a default value if no input value is present.intRetrieves the value of a named cookie and converts it to an integer.intRetrieves the value of a named cookie and converts it to an integer, using a default value if no input value is present.longcookieLong(String name) Retrieves the value of a named cookie and converts it to a long.longcookieLong(String name, long defaultValue) Retrieves the value of a named cookie and converts it to a long, using a default value if no input value is present.Retrieves the names of the cookies.cookieValue(String name) Retrieves the value of a cookie.cookieValue(String name, String defaultValue) Retrieves the value of a named cookie, using a default value as fallback.Retrieves all current cookies names with their values.Retrieves the CSRF token of the browser that performs this request, establishing one withensureCsrfToken()when the browser doesn't have one yet.voiddefer()Interrupts the execution in RIFE2 completely and defers it to the servlet container.voidenableTextBuffer(boolean enabled) Enables or disables the response text buffer.Retrieves the exception that was triggered during the RIFE2 web engine execution.voidEnsures that a CSRF token is established for this request, generating a new one and setting its cookie when the browser doesn't have one yet.Retrieves an uploaded file.Retrieves the list of uploaded file names.files()Retrieves the files that were uploaded in this context.Retrieves all files that have been uploaded for a particular name.voidflush()Forces all the streamed content to be output to the client.static ContextfromTemplate(Template template) Retrieves the context that was stored in a template attribute.gateUrl()Retrieves the URL portion that corresponds to the entrance gate of the RIFE2 web engine, this is usually equivalent with the HTTP request context path.voidgenerateEmptyForm(Template template, Class beanClass) Generates a form that corresponds to an empty instance of a bean class.voidgenerateEmptyForm(Template template, Class beanClass, String prefix) Generates a form that corresponds to an empty instance of a bean class.voidgenerateForm(Template template, Object beanInstance) Generates a form that corresponds to a bean instance.voidgenerateForm(Template template, Object beanInstance, String prefix) Generates a form that corresponds to a bean instance.booleanhasAttribute(String name) Checks if a request attribute exists.booleanIndicates whether a continuation identifier is availablebooleanChecks whether a cookie is present.booleanIndicates whether a CSRF token is available for this request, either because one was already established while processing it, or because the browser sent its token cookie.booleanChecks if a particular file has been uploaded in this context.booleanhasParameterValue(String name) Checks whether a value has been provided to a parameter.booleanhasProperty(String name) Checks for the existence of a property in this context'sHierarchicalProperties.Returns the value of the specified request header as a String.longheaderDate(String name) Returns the value of the specified request header as a long value that represents a date.intReturns the value of the specified request header as an int.Returns a list of all the header names in the request.Returns all the values of the specified request header as a list ofStringobjects.Returns the browser's current URL at the time of the htmx request, from theHX-Current-URLrequest header.voidhxLocation(String url) Tells htmx to do a client-side redirect to a new location without a full page reload, by setting theHX-Locationresponse header.voidhxLocation(HxLocation location) Tells htmx to do a client-side redirect with navigation context, by setting theHX-Locationresponse header to its JSON form.voidhxLocation(Route route) Tells htmx to do a client-side redirect to a route without a full page reload, by setting theHX-Locationresponse header.voidTells htmx not to push a URL into the browser history for this response, by setting theHX-Push-Urlresponse header tofalse.voidTells htmx not to replace the current URL in the browser history for this response, by setting theHX-Replace-Urlresponse header tofalse.hxPrompt()Returns the user's response to anhx-prompt, from theHX-Promptrequest header.voidTells htmx to push a new URL into the browser history, by setting theHX-Push-Urlresponse header.voidTells htmx to push a route's URL into the browser history by setting theHX-Push-Urlresponse header.voidhxRedirect(String url) Tells htmx to do a full-page redirect, by setting theHX-Redirectresponse header.voidhxRedirect(Route route) Tells htmx to do a full-page redirect to a route, by setting theHX-Redirectresponse header.voidTells htmx to refresh the whole page, by setting theHX-Refreshresponse header.voidhxReplaceUrl(String url) Tells htmx to replace the current URL in the browser history, by setting theHX-Replace-Urlresponse header.voidhxReplaceUrl(Route route) Tells htmx to replace the current URL in the browser history with a route's URL, by setting theHX-Replace-Urlresponse header.voidhxReselect(String cssSelector) Tells htmx to select only part of the response for swapping, by setting theHX-Reselectresponse header to a CSS selector.voidTells htmx to change how the response is swapped in, by setting theHX-Reswapresponse header to anhx-swapvalue such asouterHTMLorbeforeend.voidhxRetarget(String cssSelector) Tells htmx to swap the response into a different target than the triggering element's, by setting theHX-Retargetresponse header to a CSS selector.hxTarget()Returns theidof the target element of an htmx request, from theHX-Targetrequest header.voidTriggers a client-side event as soon as the response is received, by adding it to theHX-Triggerresponse header.voidTriggers a client-side event with a data payload as soon as the response is received, by adding it to theHX-Triggerresponse header.voidhxTriggerAfterSettle(String event) Triggers a client-side event after the settle step, by adding it to theHX-Trigger-After-Settleresponse header.voidhxTriggerAfterSettle(String event, Object data) Triggers a client-side event with a data payload after the settle step, by adding it to theHX-Trigger-After-Settleresponse header.voidhxTriggerAfterSwap(String event) Triggers a client-side event after the swap step, by adding it to theHX-Trigger-After-Swapresponse header.voidhxTriggerAfterSwap(String event, Object data) Triggers a client-side event with a data payload after the swap step, by adding it to theHX-Trigger-After-Swapresponse header.Returns theidof the element that triggered an htmx request, from theHX-Triggerrequest header.Returns thenameof the element that triggered an htmx request, from theHX-Trigger-Namerequest header.booleanisFileEmpty(String name) Checks if an uploaded file wasn't sent or if it is empty.booleanIndicates whether the current request was made by an htmx-boosted link or form, reading theHX-Boostedheader.booleanIndicates whether the current request is htmx restoring a page from its history after a cache miss, reading theHX-History-Restore-Requestheader.booleanIndicates whether the current request was issued by htmx.booleanisParameterEmpty(String name) Checks whether a parameter is empty.locale()Returns the preferredLocalethat the client will accept content in, based on theAccept-Languageheader.locales()Returns a list ofLocaleobjects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on theAccept-Language} header.method()Returns the HTTPRequestMethodwith which this context's request was made.voidnext()Interrupts the execution in this element, moving processing on to the next element in the before/route/after chainReturns an output stream suitable for writing binary data in the response.Retrieves the value of a parameter.Retrieves the value of a parameter and returns a default value if no parameter value is presentbooleanparameterBoolean(String name) Retrieves the value of a parameter and converts it to a boolean.booleanparameterBoolean(String name, boolean defaultValue) Retrieves the value of a parameter and converts it to a boolean, using a default value if no parameter value is present.doubleparameterDouble(String name) Retrieves the value of a parameter and converts it to a double.doubleparameterDouble(String name, double defaultValue) Retrieves the value of a parameter and converts it to a double, using a default value if no parameter value is present.double[]parameterDoubles(String name) Retrieves the values of a parameter as an array of doubles.floatparameterFloat(String name) Retrieves the value of a parameter and converts it to a float.floatparameterFloat(String name, float defaultValue) Retrieves the value of a parameter and converts it to a float, using a default value if no parameter value is present.float[]parameterFloats(String name) Retrieves the values of a parameter as an array of floats.intparameterInt(String name) Retrieves the value of a parameter and converts it to an integer.intparameterInt(String name, int defaultValue) Retrieves the value of a parameter and converts it to an integer, using a default value if no parameter value is present.int[]parameterInts(String name) Retrieves the values of a parameter as an array of integers.longparameterLong(String name) Retrieves the value of a parameter and converts it to a long.longparameterLong(String name, long defaultValue) Retrieves the value of a parameter and converts it to a long, using a default value if no parameter value is present.long[]parameterLongs(String name) Retrieves the values of a parameter as an array of longs.Retrieves the names of all the parameters that are present.Retrieves the parameters that were sent to this context.<BeanType> BeanTypeparametersBean(Class<BeanType> beanClass) Creates an instance of a bean and populates the properties with the parameter values.<BeanType> BeanTypeparametersBean(Class<BeanType> beanClass, String prefix) Creates an instance of a bean and populates the properties with the parameter values, taking the provided prefix into account.<BeanType> BeanTypeparametersBean(Class<BeanType> beanClass, String prefix, String group) Creates an instance of a bean and populates the properties of one of its validation groups with the parameter values that were sent.voidparametersBean(Object bean) Fills the properties of an existing bean with the parameter values.voidparametersBean(Object bean, String prefix) Fills the properties of an existing bean with the parameter values that were sent, taking the provided prefix into account.voidparametersBean(Object bean, String prefix, String group) Fills the properties of a validation group of an existing bean with the parameter values that were sent.String[]parameterValues(String name) Retrieves the values of a parameter.pathInfo()The pathinfo that was captured or matched.final voidpause()Pauses the execution of the element and creates a new continuation.voidSets up the current response to prevent all caching of the response by the client.voidPrints the string representation of an object to the request text output.voidPrints a template to the response.voidprintBlock(Template template, String blockId) Prints a single named block of a template to the response.voidprintHtmxFragment(Template template, String blockId) Prints a template as a full page or as one of its blocks, depending on whether the request came from htmx.The hierarchical properties accessible to this context.Retrieve a property from this context'sHierarchicalProperties.Returns a collection of the names in this context'sHierarchicalProperties.protocol()Returns the name and version of the protocol the request uses in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1.voidInterrupts the execution in this element and redirects the client to another URL.voidInterrupts the execution in this element and redirects the client to another URL.Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.Returns the fully qualified name of the client or the last proxy that sent the request.Returns the login of the user making this request.voidremoveAttribute(String name) Removes an attribute from this request.voidremoveCookie(String name) Removes a cookie with path"/".voidremoveCookie(String path, String name) Removes a cookie with given path and name.voidremoveForm(Template template, Class beanClass) Removes a generated form, leaving the builder value tags empty again as if this form had never been generated.voidremoveForm(Template template, Class beanClass, String prefix) Removes a generated form, leaving the builder value tags empty again as if this form had never been generated.voidremoveParameter(String name) Removes a name parameter that was previously set.request()The request of this context.voidrespond()Interrupts the execution in this element, stops processing any other element, and sends the current response directly to the client.response()The response of this context.route()The route of this context.router()The router in which this context's route was defined.scheme()Returns the name of the scheme used to make this request.booleansecure()Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.selectParameter(Template template, String name, String[] values) Sets a select box option, a radio button or a checkbox to selected or checked.Returns the host name of the server to which the request was sent.intReturns the port number to which the request was sent.serverRootUrl(int port) Returns the root URL of the server that is running this web applications.session()Returns the current session associated with this request, or if the request does not have a session, creates one.session(boolean create) Returns the currentSessionassociated with this request or, if there is no current session andcreateis true, returns a new session.voidsetAttribute(String name, Object object) Stores an attribute in this request.voidsetContentLength(int length) Sets the length of the content body in the response.voidsetContentType(String contentType) Sets the content type of the response being sent to the client.voidsetDateHeader(String name, long date) Adds a response header with the given name and date-value.voidAdds a response header with the given name and integer value.voidSets a response header with the given name and value.voidSets the locale of the response.voidsetParameter(String name, Object value) Sets a named parameter value for URL generation withurlFor(rife.engine.Route)or the `route:` filtered template value tags.voidsetParametersBean(Object bean) Sets named parameters values from bean properties for URL generation withurlFor(rife.engine.Route)or the `route:` filtered template value tags.voidsetParametersBean(Object bean, String prefix) Sets named parameters values from bean properties for URL generation withurlFor(rife.engine.Route)or the `route:` filtered template value tags.voidsetStatus(int statusCode) Sets the status code for the response.site()The active site this context is executing in.sse()Turns the response into a server-sent events (SSE) stream that remains under the control of this element.sse(SseBroadcaster broadcaster) Turns the response into a server-sent events (SSE) stream that is detached from this element and registered with a broadcaster.template()Instantiates an HTML template with the name corresponding to the identifier of this route's element.Instantiates an HTML template with a given name.Instantiates an HTML template with a given name and encoding.Instantiates an JSON template with the name corresponding to the identifier of this route's element.templateJson(String name) Instantiates an JSON template with a given name.templateJson(String name, String encoding) Instantiates an JSON template with a given name and encoding.Instantiates an SVG template with the name corresponding to the identifier of this route's element.templateSvg(String name) Instantiates an SVG template with a given name.templateSvg(String name, String encoding) Instantiates an SVG template with a given name and encoding.Instantiates a TXT template with the name corresponding to the identifier of this route's element.templateTxt(String name) Instantiates a TXT template with a given name.templateTxt(String name, String encoding) Instantiates a TXT template with a given name and encoding.Instantiates an XML template with the name corresponding to the identifier of this route's element.templateXml(String name) Instantiates an XML template with a given name.templateXml(String name, String encoding) Instantiates an XML template with a given name and encoding.booleanIndicates whether the response text buffer is enabled or disabled.Start building a URL towards a particular route.voidDeclares that the response depends on one or more request headers, by adding each to the response'sVaryheader so a cache keeps responses that differ on those headers apart.voidVerifies that this request provides the CSRF token of the browser that performs it.Returns the root URL of this web application.webappRootUrl(int port) Returns the root URL of this web application.
-
Field Details
-
DEFAULT_BOOLEAN
public static final boolean DEFAULT_BOOLEAN- See Also:
-
DEFAULT_INTEGER
public static final int DEFAULT_INTEGER- See Also:
-
DEFAULT_LONG
public static final long DEFAULT_LONG- See Also:
-
DEFAULT_DOUBLE
public static final double DEFAULT_DOUBLE- See Also:
-
DEFAULT_FLOAT
public static final float DEFAULT_FLOAT- See Also:
-
SC_NOT_MODIFIED
public static final int SC_NOT_MODIFIEDStatus code (304) indicating that a conditional GET operation found that the resource was available and not modified.- See Also:
-
SC_FORBIDDEN
public static final int SC_FORBIDDENStatus code (403) indicating the server understood the request but refused to fulfill it.- See Also:
-
SC_INTERNAL_SERVER_ERROR
public static final int SC_INTERNAL_SERVER_ERRORStatus code (500) indicating an error inside the HTTP server which prevented it from fulfilling the request.- See Also:
-
-
Method Details
-
site
The active site this context is executing in.- Returns:
- the currently active site
- Since:
- 1.0
-
request
The request of this context.Most request methods have direct counterparts in the context for easier and more convenient usage.
- Returns:
- this context's request
- Since:
- 1.0
-
response
The response of this context.Most response methods have direct counterparts in the context for easier and more convenient usage.
- Returns:
- this context's response
- Since:
- 1.0
-
pathInfo
The pathinfo that was captured or matched.The slash separated between the route path in the pathinfo will have been stripped already.
- Returns:
- the captured or matching pathinfo; or
nullif no pathinfo was captured or matched - Since:
- 1.0
-
route
The route of this context.- Returns:
- this context's route; or
nullif the context doesn't belong to a specific route - Since:
- 1.0
-
router
The router in which this context's route was defined.- Returns:
- this context's route's router; or
nullif the context doesn't belong to a specific route - Since:
- 1.0
-
properties
The hierarchical properties accessible to this context.- Returns:
- this context's hierarchical properties; or
nullif those properties can't be found - Since:
- 1.0
-
property
Retrieve a property from this context'sHierarchicalProperties.- Returns:
- the requested property; or
nullif it doesn't exist - Since:
- 1.0
-
hasProperty
Checks for the existence of a property in this context'sHierarchicalProperties.- Returns:
trueif the property exists; orfalseotherwise- Since:
- 1.0
-
propertyNames
Returns a collection of the names in this context'sHierarchicalProperties.- Returns:
- the requested collection of names
- Since:
- 1.0
-
pause
public final void pause()Pauses the execution of the element and creates a new continuation.The next request will resume exactly at the same location with a completely restored call stack and variable stack.
- Since:
- 1.0
-
hasContinuationId
public boolean hasContinuationId()Indicates whether a continuation identifier is available- Returns:
truewhen a continuation identifier is available; orfalseotherwise- Since:
- 1.0
-
continuationId
Returns the unique identifier of the current continuation.- Returns:
- the unique identifier of the current continuation; or
nullif no continuation is active - Since:
- 1.0
-
print
Prints the string representation of an object to the request text output. The string representation will be created through aString.valueOf(value)call.- Parameters:
object- the object that will be output- Throws:
EngineException- if an error occurs during the output of the contentSseOutputRefusedException- when an SSE connection has been established for this request- Since:
- 1.0
- See Also:
-
print
Prints a template to the response.If no response content type was set yet, the template's content type will be used.
Printing a template will automatically process all the filtered tags.
Printing a template instead of the string representation of its content has many advantages, the biggest one being that the out-of-container testing API will have access to this template instance, allowing you to assert of value content, instead of having to parse a response.
- Parameters:
template- the template to print- Throws:
TemplateException- if an error occurs while processing the templateEngineException- if an error occurs during the output of the contentSseOutputRefusedException- when an SSE connection has been established for this request- Since:
- 1.0
-
printBlock
Prints a single named block of a template to the response.The template's filtered tags (values, routes, application and context tags) are processed just as with
print(Template), but only the content of the requested block is written out, not the whole template. This is the low-level primitive for sending HTML fragments to htmx and other hypermedia libraries.When you want to serve the full page on a normal request and just a block on an htmx request, you should use
printHtmxFragment(rife.template.Template, java.lang.String), which makes that choice for you and which, unlike a bareisHxRequest()check, still serves the full page when htmx is restoring a page from its history. This method is what you use when you specifically want a block, such as an htmx out-of-band update. Give the block's root element anhx-swap-oobattribute in the template and print it after the main content, so that htmx swaps it in wherever it belongs.c.print(mainTemplate); // the primary swap c.printBlock(mainTemplate, "cartBadge"); // an hx-swap-oob block, updated too
- Parameters:
template- the template whose block should be printedblockId- the id of the block to print- Throws:
TemplateException- if an error occurs while processing the templateEngineException- if an error occurs during the outputSseOutputRefusedException- when an SSE connection has been established for this request- Since:
- 1.10
- See Also:
-
printHtmxFragment
Prints a template as a full page or as one of its blocks, depending on whether the request came from htmx.This is the whole "one element serves both" pattern in a single call: on a normal request the entire template is printed with
print(Template), and on anhtmx requestonly the named block is printed withprintBlock(rife.template.Template, java.lang.String). Pair it with a block value (<!--bv blockId-->) and the same element handles the full page and the fragment with no branching of its own:get("/books", c -> { var t = c.template("books"); // ... fill it ... c.printHtmxFragment(t, "list"); // full page normally, just the list to htmx });An htmx
history-restoration requestis deliberately served the full page, since htmx replaces the whole document when restoring from history and a fragment would corrupt back/forward navigation.Because the response genuinely differs on these headers, this adds
HX-RequestandHX-History-Restore-Requestto the response'sVaryheader, so a cache never hands the full page to an htmx request or the other way around. Using this instead of a hand-writtenisHxRequest()branch keeps the history-restoration guard and theVaryheader from being forgotten.- Parameters:
template- the template to printblockId- the id of the block to send on an htmx request- Throws:
TemplateException- if an error occurs while processing the templateEngineException- if an error occurs during the outputSseOutputRefusedException- when an SSE connection has been established for this request- Since:
- 1.10
- See Also:
-
fromTemplate
Retrieves the context that was stored in a template attribute.Each template that was obtained through a context, automatically has the context store itself in the template as an attribute. This convenience method makes it easy to retrieve that context elsewhere.
- Returns:
- the current context stored in a template attribute.
- Since:
- 1.8.0
-
template
Instantiates an HTML template with the name corresponding to the identifier of this route's element.For lambda elements, this will be the path of the route and for class elements this will be the shortened uncapitalized name of the class.
- Returns:
- the HTML template if it was found.
- Throws:
TemplateException- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
template
Instantiates an HTML template with a given name.- Parameters:
name- the template name- Returns:
- the HTML template if it was found.
- Throws:
TemplateException- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
template
Instantiates an HTML template with a given name and encoding.- Parameters:
name- the template nameencoding- the template's encoding- Returns:
- the HTML template if it was found.
- Throws:
TemplateException- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateTxt
Instantiates a TXT template with the name corresponding to the identifier of this route's element.For lambda elements, this will be the path of the route and for class elements this will be the shortened uncapitalized name of the class.
- Returns:
- the TXT template if it was found.
- Throws:
TemplateException- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateTxt
Instantiates a TXT template with a given name.- Parameters:
name- the template name- Returns:
- the TXT template if it was found.
- Throws:
TemplateException- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateTxt
Instantiates a TXT template with a given name and encoding.- Parameters:
name- the template nameencoding- the template's encoding- Returns:
- the TXT template if it was found.
- Throws:
TemplateException- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateXml
Instantiates an XML template with the name corresponding to the identifier of this route's element.For lambda elements, this will be the path of the route and for class elements this will be the shortened uncapitalized name of the class.
- Returns:
- the XML template if it was found.
- Throws:
TemplateException- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateXml
Instantiates an XML template with a given name.- Parameters:
name- the template name- Returns:
- the XML template if it was found.
- Throws:
TemplateException- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateXml
Instantiates an XML template with a given name and encoding.- Parameters:
name- the template nameencoding- the template's encoding- Returns:
- the XML template if it was found.
- Throws:
TemplateException- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateJson
Instantiates an JSON template with the name corresponding to the identifier of this route's element.For lambda elements, this will be the path of the route and for class elements this will be the shortened uncapitalized name of the class.
- Returns:
- the JSON template if it was found.
- Throws:
TemplateException- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateJson
Instantiates an JSON template with a given name.- Parameters:
name- the template name- Returns:
- the JSON template if it was found.
- Throws:
TemplateException- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateJson
Instantiates an JSON template with a given name and encoding.- Parameters:
name- the template nameencoding- the template's encoding- Returns:
- the JSON template if it was found.
- Throws:
TemplateException- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateSvg
Instantiates an SVG template with the name corresponding to the identifier of this route's element.For lambda elements, this will be the path of the route and for class elements this will be the shortened uncapitalized name of the class.
- Returns:
- the SVG template if it was found.
- Throws:
TemplateException- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateSvg
Instantiates an SVG template with a given name.- Parameters:
name- the template name- Returns:
- the SVG template if it was found.
- Throws:
TemplateException- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateSvg
Instantiates an SVG template with a given name and encoding.- Parameters:
name- the template nameencoding- the template's encoding- Returns:
- the SVG template if it was found.
- Throws:
TemplateException- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
gateUrl
Retrieves the URL portion that corresponds to the entrance gate of the RIFE2 web engine, this is usually equivalent with the HTTP request context path.- Returns:
- the URL of the web engine gate
- Since:
- 1.0
-
serverRootUrl
Returns the root URL of the server that is running this web applications.This includes the protocol, the server name and the server port, for example:
http://www.somehost.com:8080.- Parameters:
port- the server port to use, or-1to use the sane port as the active request- Returns:
- the server's root url
- Since:
- 1.0
-
webappRootUrl
Returns the root URL of this web application.This includes the protocol, the server name and the server port, and the gate URL.
- Returns:
- this web application's root URL
- Since:
- 1.0
-
webappRootUrl
Returns the root URL of this web application.This includes the protocol, the server name and the server port, and the gate URL.
- Parameters:
port- the server port to use, or-1to use the sane port as the active request- Returns:
- this web application's root URL
- Since:
- 1.0
-
urlFor
Start building a URL towards a particular route.The result is a instance that can be used for further customization of the URL, if needed.
- Parameters:
route- the target route- Returns:
- an instance of
- Since:
- 1.0
-
engineException
Retrieves the exception that was triggered during the RIFE2 web engine execution.- Returns:
- the triggered exception; or
nullif no exception was triggered - Since:
- 1.0
-
selectParameter
Sets a select box option, a radio button or a checkbox to selected or checked.This method delegates all logic to the
FormBuilder.selectParameter(Template, String, String[])method of the provided template instance.- Parameters:
template- the template instance where the selection should happenname- the name of the parametervalues- the values that should be selected or checked- Returns:
- a list with the identifiers of the template values that have
been set, this is never
null, when no values are set an empty list is returned - Since:
- 1.0
- See Also:
-
generateForm
Generates a form that corresponds to a bean instance.- Parameters:
template- the template instance where the generation should happenbeanInstance- the instance of the bean that should be used to generate the form- Since:
- 1.0
- See Also:
-
generateForm
Generates a form that corresponds to a bean instance.This method delegates all logic to the
FormBuilder.generateForm(Template, Object, Map, String)method of the provided template instance.- Parameters:
template- the template instance where the generation should happenbeanInstance- the instance of the bean that should be used to generate the formprefix- the prefix that will be prepended to all bean property names- Since:
- 1.0
- See Also:
-
generateEmptyForm
Generates a form that corresponds to an empty instance of a bean class.- Parameters:
template- the template instance where the generation should happenbeanClass- the class of the bean that should be used to generate the form- Since:
- 1.0
- See Also:
-
generateEmptyForm
Generates a form that corresponds to an empty instance of a bean class.An 'empty' instance is an object that has been created by calling the default constructor of the bean class, without making any additional changes to it afterward.
This method delegates all logic to the
FormBuilder.generateForm(Template, Class, Map, String)method of the provided template instance.- Parameters:
template- the template instance where the generation should happenbeanClass- the class of the bean that should be used to generate the formprefix- the prefix that will be prepended to all bean property names- Since:
- 1.0
- See Also:
-
removeForm
Removes a generated form, leaving the builder value tags empty again as if this form had never been generated.- Parameters:
template- the template instance where the form should be removed frombeanClass- the class of the bean that should be used to remove the form- Since:
- 1.0
- See Also:
-
removeForm
Removes a generated form, leaving the builder value tags empty again as if this form had never been generated.This method delegates all logic to the
FormBuilder.removeForm(Template, Class, String)method of the provided template instance.- Parameters:
template- the template instance where the form should be removed frombeanClass- the class of the bean that should be used to remove the formprefix- the prefix that will be prepended to all bean property names- Since:
- 1.0
- See Also:
-
defer
Interrupts the execution in RIFE2 completely and defers it to the servlet container.If RIFE2 is being run as a filter, it will execute the next filter in the chain.
If RIFE2 is being run as a servlet, the status code
404: Not Foundwill be sent to the client.- Throws:
DeferException- an exception that is used to immediately interrupt the execution, don't catch this exception- Since:
- 1.0
-
redirect
Interrupts the execution in this element and redirects the client to another URL.- Parameters:
url- the URL to which the request will be redirected,String.valueOf()will be called with this object, so a variety of types can be used- Throws:
RedirectException- an exception that is used to immediately interrupt the execution, don't catch this exception- Since:
- 1.0
-
redirect
Interrupts the execution in this element and redirects the client to another URL.- Parameters:
route- the route to which the request will be redirected- Throws:
RedirectException- an exception that is used to immediately interrupt the execution, don't catch this exception- Since:
- 1.0
-
respond
public void respond()Interrupts the execution in this element, stops processing any other element, and sends the current response directly to the client.- Throws:
RespondException- an exception that is used to immediately interrupt the execution, don't catch this exception- Since:
- 1.0
-
next
public void next()Interrupts the execution in this element, moving processing on to the next element in the before/route/after chain- Throws:
NextException- an exception that is used to immediately interrupt the execution, don't catch this exception- Since:
- 1.0
-
preventCaching
public void preventCaching()Sets up the current response to prevent all caching of the response by the client.- Since:
- 1.0
-
method
Returns the HTTPRequestMethodwith which this context's request was made.- Returns:
- the
RequestMethodof this context's request - Since:
- 1.0
-
parameters
Retrieves the parameters that were sent to this context.- Returns:
- a
Mapwith all the parameter names and values - Since:
- 1.0
-
hasParameterValue
Checks whether a value has been provided to a parameter.- Parameters:
name- the name of the parameter- Returns:
trueif the parameter has a value; orfalseotherwise- Since:
- 1.0
- See Also:
-
isParameterEmpty
Checks whether a parameter is empty.- Parameters:
name- the name of the parameter- Returns:
trueif the parameter is empty; orfalseotherwise- Since:
- 1.0
- See Also:
-
parameter
Retrieves the value of a parameter.- Parameters:
name- the name of the parameter- Returns:
- the value of the parameter; or
nullif no value is present for this parameter - Since:
- 1.0
- See Also:
-
parameter
Retrieves the value of a parameter and returns a default value if no parameter value is present- Parameters:
name- the name of the parameterdefaultValue- the default value that will be used when no parameter value is present- Returns:
- the parameter value; or
the default value if no parameter value is present
- Since:
- 1.0
- See Also:
-
parameterNames
Retrieves the names of all the parameters that are present.- Returns:
- the list with the parameter names
- Since:
- 1.0
- See Also:
-
parameterValues
Retrieves the values of a parameter.- Parameters:
name- the name of the parameter- Since:
- 1.0
- See Also:
-
parameterBoolean
Retrieves the value of a parameter and converts it to a boolean.- Parameters:
name- the name of the parameter- Returns:
- the converted parameter value; or
falseif no parameter value is present or if the parameter value is not a valid boolean - Since:
- 1.0
- See Also:
-
parameterBoolean
Retrieves the value of a parameter and converts it to a boolean, using a default value if no parameter value is present.- Parameters:
name- the name of the parameterdefaultValue- the default value that will be used when no parameter value is present- Returns:
- the converted parameter value; or
the default value if no parameter value is present
- Since:
- 1.0
- See Also:
-
parameterInt
Retrieves the value of a parameter and converts it to an integer.- Parameters:
name- the name of the parameter- Returns:
- the converted parameter value; or
0if no parameter value is present or if the parameter value is not a valid integer - Since:
- 1.0
- See Also:
-
parameterInt
Retrieves the value of a parameter and converts it to an integer, using a default value if no parameter value is present.- Parameters:
name- the name of the parameterdefaultValue- the default value that will be used when no parameter value is present- Returns:
- the converted parameter value; or
the default value if no parameter value is present
- Since:
- 1.0
- See Also:
-
parameterLong
Retrieves the value of a parameter and converts it to a long.- Parameters:
name- the name of the parameter- Returns:
- the converted parameter value; or
0Lif no parameter value is present or if the parameter value is not a valid long - Since:
- 1.0
- See Also:
-
parameterLong
Retrieves the value of a parameter and converts it to a long, using a default value if no parameter value is present.- Parameters:
name- the name of the parameterdefaultValue- the default value that will be used when no parameter value is present- Returns:
- the converted parameter value; or
the default value if no parameter value is present
- Since:
- 1.0
- See Also:
-
parameterDouble
Retrieves the value of a parameter and converts it to a double.- Parameters:
name- the name of the parameter- Returns:
- the converted parameter value; or
0.0dif no parameter value is present or if the parameter value is not a valid double - Since:
- 1.0
- See Also:
-
parameterDouble
Retrieves the value of a parameter and converts it to a double, using a default value if no parameter value is present.- Parameters:
name- the name of the parameterdefaultValue- the default value that will be used when no parameter value is present- Returns:
- the converted parameter value; or
the default value if no parameter value is present
- Since:
- 1.0
- See Also:
-
parameterFloat
Retrieves the value of a parameter and converts it to a float.- Parameters:
name- the name of the parameter- Returns:
- the converted parameter value; or
0.0fif no parameter value is present or if the parameter value is not a valid float - Since:
- 1.0
- See Also:
-
parameterFloat
Retrieves the value of a parameter and converts it to a float, using a default value if no parameter value is present.- Parameters:
name- the name of the parameterdefaultValue- the default value that will be used when no parameter value is present- Returns:
- the converted parameter value; or
the default value if no parameter value is present
- Since:
- 1.0
- See Also:
-
parameterInts
Retrieves the values of a parameter as an array of integers.- Parameters:
name- the name of the parameter- Returns:
- an integer array with all the parameter values; or
nullif no parameter values are present - Since:
- 1.0
- See Also:
-
parameterLongs
Retrieves the values of a parameter as an array of longs.- Parameters:
name- the name of the parameter- Returns:
- a long array with all the parameter values; or
nullif no parameter values are present - Since:
- 1.0
- See Also:
-
parameterFloats
Retrieves the values of a parameter as an array of floats.- Parameters:
name- the name of the parameter- Returns:
- a float array with all the parameter values; or
nullif no parameter values are present - Since:
- 1.0
- See Also:
-
parameterDoubles
Retrieves the values of a parameter as an array of doubles.- Parameters:
name- the name of the parameter- Returns:
- a double array with all the parameter values; or
nullif no parameter values are present - Since:
- 1.0
- See Also:
-
parametersBean
Creates an instance of a bean and populates the properties with the parameter values.This bean is not serialized or de-serialized, each property corresponds to a parameter and is individually sent by the client.
- Parameters:
beanClass- the class of the submission bean- Returns:
- the populated bean instance
- Throws:
EngineException- Since:
- 1.0
- See Also:
-
parametersBean
public <BeanType> BeanType parametersBean(Class<BeanType> beanClass, String prefix) throws EngineException Creates an instance of a bean and populates the properties with the parameter values, taking the provided prefix into account.This bean is not serialized or de-serialized, each property corresponds to a parameter and is individually sent by the client.
- Parameters:
beanClass- the class of the submission beanprefix- the prefix that will be put in front of each property name- Returns:
- the populated bean instance
- Throws:
EngineException- Since:
- 1.0
- See Also:
-
parametersBean
Fills the properties of an existing bean with the parameter values.- Parameters:
bean- the submission bean instance that will be filled- Throws:
EngineException- Since:
- 1.0
- See Also:
-
parametersBean
Fills the properties of an existing bean with the parameter values that were sent, taking the provided prefix into account.A parameter that is present with an empty value will reset the property to the value of a new bean instance, while an absent parameter will leave the property untouched.
- Parameters:
bean- the submission bean instance that will be filledprefix- the prefix that will be put in front of each property name- Throws:
EngineException- Since:
- 1.0
- See Also:
-
parametersBean
public <BeanType> BeanType parametersBean(Class<BeanType> beanClass, String prefix, String group) throws EngineException Creates an instance of a bean and populates the properties of one of its validation groups with the parameter values that were sent.This does the same as
parametersBean(Object, String, String), but with a newly created bean instance.- Parameters:
beanClass- the class of the submission beanprefix- the prefix that will be put in front of each property name, ornullgroup- the name of the validation group whose properties will be populated- Returns:
- the populated bean instance
- Throws:
EngineException- Since:
- 1.10
- See Also:
-
parametersBean
Fills the properties of a validation group of an existing bean with the parameter values that were sent.The validation group declares which properties are part of the form. Only those properties will be populated, and a property whose parameter is absent will be reset instead of keeping its current value: a boolean property becomes
falsesince browsers don't send checkboxes that aren't checked, the other properties are reset to the value of a new bean instance. A restored bean will thus reflect exactly what the form submitted, while the properties outside of the group preserve their current values.Each property is populated through a single transport: a property with a
fileconstraint is only assigned from file uploads, while the other properties are only assigned from regular parameter values. A file property is left untouched when no upload actually arrived, an absent file input never clears the stored content.Since every property of the group is expected to be part of the form, a group should only contain the properties that are actually submitted. Controls that the browser doesn't send, like disabled ones, and partial submissions of a group's form will reset the properties that didn't arrive.
- Parameters:
bean- the submission bean instance that will be filledprefix- the prefix that will be put in front of each property name, ornullgroup- the name of the validation group whose properties will be populated- Throws:
EngineException- Since:
- 1.10
- See Also:
-
body
Retrieves the body of this context's request as a string.- Returns:
- the string of the request body
- Since:
- 1.0
- See Also:
-
bodyAsBytes
public byte[] bodyAsBytes()Retrieves the body of this context's request as a byte array.- Returns:
- the byte array of the request body
- Since:
- 1.0
- See Also:
-
fileNames
Retrieves the list of uploaded file names.- Returns:
- the set of uploaded file names
- Since:
- 1.0
- See Also:
-
isFileEmpty
Checks if an uploaded file wasn't sent or if it is empty.- Parameters:
name- the name of the file- Since:
- 1.0
- See Also:
-
files
Retrieves the files that were uploaded in this context.- Returns:
- a
Mapwith all the uploaded files - Since:
- 1.0
- See Also:
-
hasFile
Checks if a particular file has been uploaded in this context.- Parameters:
name- the name of the file- Returns:
trueif the file was uploaded; orfalseotherwise- Since:
- 1.0
- See Also:
-
file
Retrieves an uploaded file.- Parameters:
name- the name of the file- Returns:
- the uploaded file; or
nullif no file was uploaded - Since:
- 1.0
- See Also:
-
files
Retrieves all files that have been uploaded for a particular name.- Parameters:
name- the name of the file- Returns:
- the uploaded files; or
nullif no files were uploaded for that name - Since:
- 1.0
- See Also:
-
hasCookie
Checks whether a cookie is present.- Parameters:
name- the name of the cookie- Returns:
trueif the cookie was present; orfalseotherwise- Since:
- 1.0
- See Also:
-
cookieNames
Retrieves the names of the cookies.- Returns:
- a list of strings with the cookie names
- Since:
- 1.0
- See Also:
-
cookieValue
Retrieves the value of a cookie.- Parameters:
name- the name of the cookie- Returns:
- the value of the cookie; or
nullif no such cookie is present - Since:
- 1.0
- See Also:
-
cookieValues
Retrieves all current cookies names with their values.- Returns:
- a new map of all the current cookies names with their values
- Since:
- 1.0
- See Also:
-
cookieValue
Retrieves the value of a named cookie, using a default value as fallback.- Parameters:
name- the name of the cookiedefaultValue- the default value that will be used when no cookie value is present- Returns:
- the cookie value; or
the default value if no cookie value is present
- Since:
- 1.0
- See Also:
-
cookieBoolean
Retrieves the value of a named cookie and converts it to a boolean.- Parameters:
name- the name of the cookie- Returns:
- the converted cookie value; or
falseif no cookie value is present or if the cookie value is not a valid boolean - Since:
- 1.0
- See Also:
-
cookieBoolean
Retrieves the value of a named cookie and converts it to a boolean, using a default value if no input value is present.- Parameters:
name- the name of the cookiedefaultValue- the default value that will be used when no cookie value is present- Returns:
- the converted cookie value; or
the default value if no cookie value is present
- Since:
- 1.0
- See Also:
-
cookieInt
Retrieves the value of a named cookie and converts it to an integer.- Parameters:
name- the name of the cookie- Returns:
- the converted cookie value; or
0if no cookie value is present or if the cookie value is not a valid integer - Since:
- 1.0
- See Also:
-
cookieInt
Retrieves the value of a named cookie and converts it to an integer, using a default value if no input value is present.- Parameters:
name- the name of the cookiedefaultValue- the default value that will be used when no cookie value is present- Returns:
- the converted cookie value; or
the default value if no cookie value is present
- Since:
- 1.0
- See Also:
-
cookieLong
Retrieves the value of a named cookie and converts it to a long.- Parameters:
name- the name of the cookie- Returns:
- the converted cookie value; or
0Lif no cookie value is present or if the cookie value is not a valid long - Since:
- 1.0
- See Also:
-
cookieLong
Retrieves the value of a named cookie and converts it to a long, using a default value if no input value is present.- Parameters:
name- the name of the cookiedefaultValue- the default value that will be used when no cookie value is present- Returns:
- the converted cookie value; or
the default value if no cookie value is present
- Since:
- 1.0
- See Also:
-
cookieDouble
Retrieves the value of a named cookie and converts it to a double.- Parameters:
name- the name of the cookie- Returns:
- the converted cookie value; or
0.0dif no cookie value is present or if the cookie value is not a valid double - Since:
- 1.0
- See Also:
-
cookieDouble
Retrieves the value of a named cookie and converts it to a double, using a default value if no input value is present.- Parameters:
name- the name of the cookiedefaultValue- the default value that will be used when no cookie value is present- Returns:
- the converted cookie value; or
the default value if no cookie value is present
- Since:
- 1.0
- See Also:
-
cookieFloat
Retrieves the value of a named cookie and converts it to a float.- Parameters:
name- the name of the cookie- Returns:
- the converted cookie value; or
0.0f if no cookie value is present or if the cookie value is not a valid float - Since:
- 1.0
- See Also:
-
cookieFloat
Retrieves the value of a named cookie and converts it to a float, using a default value if no input value is present.- Parameters:
name- the name of the cookiedefaultValue- the default value that will be used when no cookie value is present- Returns:
- the converted cookie value; or
the default value if no cookie value is present
- Since:
- 1.0
- See Also:
-
attribute
Returns the value of the named attribute.- Parameters:
name- the name of the attribute- Returns:
- an Object containing the value of the attribute; or
nullif the attribute does not exist - Since:
- 1.0
- See Also:
-
hasAttribute
Checks if a request attribute exists.- Parameters:
name- aStringspecifying the name of the attributefalseotherwise- Since:
- 1.0
- See Also:
-
attributeNames
Returns a list of attribute names available to this request.- Returns:
- a list of strings containing the names of the request's attributes; or
an empty list if not attributes are present
- Since:
- 1.0
- See Also:
-
removeAttribute
Removes an attribute from this request. This method is not generally needed as attributes only persist as long as the request is being handled.- Parameters:
name- the name of the attribute to remove- Since:
- 1.0
- See Also:
-
setAttribute
Stores an attribute in this request. Attributes are reset between requests.Attribute names should follow the same conventions as package names. If the object passed in is
null, the effect is the same as callingremoveAttribute.- Parameters:
name- the name of the attribute to setobject- the object to store- Since:
- 1.0
- See Also:
-
characterEncoding
Returns the name of the character encoding used in the body of this request.- Returns:
- a
Stringcontaining the name of the character encoding; ornullif the request does not specify a character encoding - Since:
- 1.0
-
contentType
Returns the MIME type of the body of the request, or null if the type is not known.- Returns:
- a
Stringcontaining the name of the MIME type of the request; ornullif the type is not known - Since:
- 1.0
-
header
Returns the value of the specified request header as a String.- Parameters:
name- the case-insensitive name of the header- Returns:
- a
Stringwith the value of the requested header; ornullif the request does not have a header of that name - Since:
- 1.0
- See Also:
-
headerDate
Returns the value of the specified request header as a long value that represents a date. Use this method with headers that contain dates, such as If-Modified-Since.- Parameters:
name- the case-insensitive name of the header- Returns:
- a long value representing the date specified in the header expressed
as the number of milliseconds since January 1, 1970 GMT; or
-1if the named header was not included with the request - Throws:
IllegalArgumentException- if the header can't be converted to a date- Since:
- 1.0
- See Also:
-
headerInt
Returns the value of the specified request header as an int.- Parameters:
name- the case-insensitive name of the header- Returns:
- an integer expressing the value of the request header; or
-1if the request doesn't have a header of this name - Throws:
NumberFormatException- if the header value can't be converted to an int- Since:
- 1.0
- See Also:
-
headerNames
Returns a list of all the header names in the request.- Returns:
- a list of all the header names sent with this request;
if the request has no headers, an empty list will be returned
- Since:
- 1.0
- See Also:
-
headers
Returns all the values of the specified request header as a list ofStringobjects.Some headers, such as
Accept-Languagecan be sent by clients as several headers each with a different value rather than sending the header as a comma separated list.- Parameters:
name- the case-insensitive name of the header- Returns:
- a list containing the values of the requested header;
itf the request does not have any headers of that name an empty list will be returned
- Since:
- 1.0
- See Also:
-
locale
Returns the preferredLocalethat the client will accept content in, based on theAccept-Languageheader.If the client request doesn't provide an Accept-Language header, this method returns the default locale for the server.
- Returns:
- the preferred Locale for the client
- Since:
- 1.0
-
locales
Returns a list ofLocaleobjects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on theAccept-Language} header.If the client request doesn't provide an Accept-Language header, this method returns a list containing one Locale, the default locale for the server.
- Returns:
- a list of preferred Locale objects for the client
- Since:
- 1.0
-
remoteAddr
Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.- Returns:
- a String containing the IP address of the client that sent the request
- Since:
- 1.0
-
remoteUser
Returns the login of the user making this request.Whether the username is sent with each subsequent request depends on the browser and type of authentication.
- Returns:
- a String specifying the login of the user making this request; or
nullif the user login is not known - Since:
- 1.0
-
remoteHost
Returns the fully qualified name of the client or the last proxy that sent the request. If the engine cannot or chooses not to resolve the hostname (to improve performance), this method returns the dotted-string form of the IP address.- Returns:
- a String containing the fully qualified name of the client
- Since:
- 1.0
-
session
Returns the current session associated with this request, or if the request does not have a session, creates one.- Returns:
- the
Sessionassociated with this request - Since:
- 1.0
- See Also:
-
session
Returns the currentSessionassociated with this request or, if there is no current session andcreateis true, returns a new session.If
createisfalseand the request has no validSession, this method returnsnull.- Parameters:
create-trueto create a new session for this request if necessary;falseto returnnullif there's no current session- Returns:
- the
Sessionassociated with this request ornullifcreateisfalseand the request has no valid session - Since:
- 1.0
-
serverPort
public int serverPort()Returns the port number to which the request was sent.- Returns:
- an integer specifying the port number
- Since:
- 1.0
-
protocol
Returns the name and version of the protocol the request uses in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1.- Returns:
- a String containing the protocol name and version number
- Since:
- 1.0
-
scheme
Returns the name of the scheme used to make this request.- Returns:
- the name of the scheme used to make this request
- Since:
- 1.0
-
serverName
Returns the host name of the server to which the request was sent.- Returns:
- the name of the server
- Since:
- 1.0
-
contextPath
Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "". The container does not decode this string.- Returns:
- the portion of the request URI that indicates the context of the request
- Since:
- 1.0
-
secure
public boolean secure()Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.- Returns:
- a boolean indicating whether the request was made using a secure channel
- Since:
- 1.0
-
enableTextBuffer
public void enableTextBuffer(boolean enabled) Enables or disables the response text buffer. By default, it is enabled.Disabling an enabled text buffer, flushes the already buffered content first.
If the text buffer is disabled, text content will be sent immediately to the client, this can decrease performance. Unless you need to stream content in real time, it's best to leave the text buffer enabled. It will be flushed and sent in one go at the end of the request.
- Parameters:
enabled-trueto enable the text buffer; orfalseto disable it- Since:
- 1.0
- See Also:
-
textBufferEnabled
public boolean textBufferEnabled()Indicates whether the response text buffer is enabled or disabled.- Returns:
trueif the text buffer is enabled; orfalseif it is disabled- Since:
- 1.0
- See Also:
-
clearBuffer
public void clearBuffer()Clears the text buffer is it's enabled.If the text buffer is disabled, this method does nothing.
- Since:
- 1.0
-
flush
public void flush()Forces all the streamed content to be output to the client.If the text buffer is enabled, this will flush its content to the output stream first.
- Since:
- 1.0
-
outputStream
Returns an output stream suitable for writing binary data in the response.When possible and applicable, this output stream will automatically handle gzip encoding.
- Returns:
- an
OutputStreamfor binary data output - Throws:
EngineException- Since:
- 1.0
-
sse
Turns the response into a server-sent events (SSE) stream that remains under the control of this element.The response is prepared for event streaming and the headers are immediately sent to the client. The connection stays open for as long as this element is executing, so the element typically sends events in a loop until
SseConnection.isOpen()indicates that the client has disconnected.- Returns:
- the SSE connection for this response
- Throws:
SseConnectionAlreadyEstablishedException- when an SSE connection has already been established for this requestSseConnectionAfterOutputException- when response content has already been producedEngineException- Since:
- 1.10
- See Also:
-
sse
Turns the response into a server-sent events (SSE) stream that is detached from this element and registered with a broadcaster.The response is prepared for event streaming and the headers are immediately sent to the client. The element returns immediately while the connection stays open, and events are pushed to it afterwards through the broadcaster, from anywhere in the application.
- Parameters:
broadcaster- the broadcaster this connection will be registered with- Returns:
- the SSE connection for this response
- Throws:
SseConnectionAlreadyEstablishedException- when an SSE connection has already been established for this requestSseConnectionAfterOutputException- when response content has already been producedEngineException- Since:
- 1.10
- See Also:
-
ensureCsrfToken
public void ensureCsrfToken()Ensures that a CSRF token is established for this request, generating a new one and setting its cookie when the browser doesn't have one yet.Once a token is active for a request, the
route:inputs:filtered tag adds it to the forms it generates, and the token is available on its own through thecontext:csrfTokentemplate value, for the headers that JavaScript sends. TheCsrfProtectedelement calls this on the pages that display protected forms.This doesn't return the token, use
csrfToken()to obtain its value.- Since:
- 1.10
- See Also:
-
csrfToken
Retrieves the CSRF token of the browser that performs this request, establishing one withensureCsrfToken()when the browser doesn't have one yet. The same token is returned for the rest of this request.- Returns:
- the CSRF token of this browser
- Since:
- 1.10
- See Also:
-
hasCsrfToken
public boolean hasCsrfToken()Indicates whether a CSRF token is available for this request, either because one was already established while processing it, or because the browser sent its token cookie.Unlike
csrfToken()this method will not create a token, so that you can decide whether to include the token without minting one for browsers that don't have it yet. Theroute:inputs:filtered tag uses it to add the token to the forms of the pages where it's active.- Returns:
truewhen a CSRF token is available; orfalseotherwise- Since:
- 1.10
- See Also:
-
verifyCsrfToken
public void verifyCsrfToken()Verifies that this request provides the CSRF token of the browser that performs it.The token is looked up in the request parameter and in the request header that
RifeConfig.engine()configures, in that order.- Throws:
CsrfTokenMissingException- when the browser has no token cookie, or when the request provides no tokenCsrfTokenInvalidException- when the provided token doesn't correspond to the token cookie- Since:
- 1.10
- See Also:
-
setContentType
Sets the content type of the response being sent to the client.- Parameters:
contentType- the MIME type of the content- Since:
- 1.0
-
setContentLength
public void setContentLength(int length) Sets the length of the content body in the response.- Parameters:
length- an integer specifying the length of the content being returned to the client- Since:
- 1.0
-
setLocale
Sets the locale of the response.- Parameters:
locale- the locale of the response- Since:
- 1.0
-
setParameter
Sets a named parameter value for URL generation withurlFor(rife.engine.Route)or the `route:` filtered template value tags.The parameter value will be converted to a string array.
Setting parameters acts on a different collection than incoming request parameters and is used for RIFE2 state-related features like URL generation.
- Parameters:
name- the name of the parameter to setvalue- the value of the parameter- Since:
- 1.0
- See Also:
-
setParametersBean
Sets named parameters values from bean properties for URL generation withurlFor(rife.engine.Route)or the `route:` filtered template value tags.- Parameters:
bean- the bean whose properties will be set as parameters- Since:
- 1.0
- See Also:
-
setParametersBean
Sets named parameters values from bean properties for URL generation withurlFor(rife.engine.Route)or the `route:` filtered template value tags.- Parameters:
bean- the bean whose properties will be set as parametersprefix- the prefix that will be added to the parameter names- Since:
- 1.0
- See Also:
-
removeParameter
Removes a name parameter that was previously set.- Parameters:
name- the name of the parameter to remove- Since:
- 1.0
- See Also:
-
addCookie
Adds theCookiecreated by aCookieBuilderto the response. This method can be called multiple times to set more than one cookie.- Parameters:
builder- theCookieBuilderto use for building theCookie- Since:
- 1.0
-
removeCookie
Removes a cookie with path"/".- Parameters:
name- name of the cookie- Since:
- 1.0
-
removeCookie
Removes a cookie with given path and name.- Parameters:
path- path of the cookiename- name of the cookie- Since:
- 1.0
-
setHeader
Sets a response header with the given name and value.If the header had already been set, the new value overwrites the previous one.
- Parameters:
name- the name of the headervalue- the additional header value- Since:
- 1.0
-
addHeader
Adds a response header with the given name and value.This method allows response headers to have multiple values.
- Parameters:
name- the name of the headervalue- the additional header value- Since:
- 1.0
-
setDateHeader
Adds a response header with the given name and date-value. The date is specified in terms of milliseconds since the epoch.If the header had already been set, the new value overwrites the previous one.
- Parameters:
name- the name of the header to setdate- the additional date value- Since:
- 1.0
-
addDateHeader
Adds a response header with the given name and date-value. The date is specified in terms of milliseconds since the epoch.This method allows response headers to have multiple values.
- Parameters:
name- the name of the header to setdate- the additional date value- Since:
- 1.0
-
setHeader
Adds a response header with the given name and integer value.If the header had already been set, the new value overwrites the previous one.
- Parameters:
name- the name of the headervalue- the assigned integer value- Since:
- 1.0
-
addHeader
Adds a response header with the given name and integer value.This method allows response headers to have multiple values.
- Parameters:
name- the name of the headervalue- the assigned integer value- Since:
- 1.0
-
setStatus
public void setStatus(int statusCode) Sets the status code for the response.- Parameters:
statusCode- the status code- Since:
- 1.0
-
isHxRequest
public boolean isHxRequest()Indicates whether the current request was issued by htmx.This reads the
HX-Requestheader that htmx sets on every request it makes. It's a plain read with no side effects, so consulting it for logging or a decision that doesn't change the output is free.To serve a fragment to htmx and the full page otherwise, prefer
printHtmxFragment(rife.template.Template, java.lang.String): it makes that choice, guards thehistory-restorationcase, and declaresVaryfor you. You should only branch on this method yourself when that helper doesn't fit, and then declare the dependency withvaryOn("HX-Request"), since a shared cache could otherwise hand the fragment to a browser or the full page to htmx.- Returns:
truewhen this is an htmx request; orfalseotherwise- Since:
- 1.10
- See Also:
-
isHxBoosted
public boolean isHxBoosted()Indicates whether the current request was made by an htmx-boosted link or form, reading theHX-Boostedheader.This method will only read the header without having any side effects. When the response depends on it, you should declare that with
varyOn("HX-Boosted")so that a cache keeps a boosted response apart from an ordinary one.- Returns:
truewhen this is an htmx-boosted request; orfalseotherwise- Since:
- 1.10
- See Also:
-
isHxHistoryRestoreRequest
public boolean isHxHistoryRestoreRequest()Indicates whether the current request is htmx restoring a page from its history after a cache miss, reading theHX-History-Restore-Requestheader.Such a request expects the whole page instead of a fragment, since htmx replaces the entire document when it restores from history, which means that a fragment would corrupt the back and forward navigation.
printHtmxFragment(rife.template.Template, java.lang.String)will serve the full page for you. If you branch between a fragment and a page yourself withisHxRequest(), you should guard that branch with this method too, since a history restore that carries the same parameters as a fragment request would otherwise receive a fragment. This method will only read the header without having any side effects.- Returns:
truewhen this is an htmx history-restoration request; orfalseotherwise- Since:
- 1.10
- See Also:
-
hxTriggerId
Returns theidof the element that triggered an htmx request, from theHX-Triggerrequest header.- Returns:
- the triggering element's id, or
nullif absent - Since:
- 1.10
-
hxTriggerName
Returns thenameof the element that triggered an htmx request, from theHX-Trigger-Namerequest header.- Returns:
- the triggering element's name, or
nullif absent - Since:
- 1.10
-
hxTarget
Returns theidof the target element of an htmx request, from theHX-Targetrequest header.- Returns:
- the target element's id, or
nullif absent - Since:
- 1.10
-
hxCurrentUrl
Returns the browser's current URL at the time of the htmx request, from theHX-Current-URLrequest header.- Returns:
- the current URL, or
nullif absent - Since:
- 1.10
-
hxPrompt
Returns the user's response to anhx-prompt, from theHX-Promptrequest header.- Returns:
- the prompt response, or
nullif absent - Since:
- 1.10
-
hxLocation
Tells htmx to do a client-side redirect to a new location without a full page reload, by setting theHX-Locationresponse header.- Parameters:
url- the location to navigate to- Since:
- 1.10
- See Also:
-
hxLocation
Tells htmx to do a client-side redirect to a route without a full page reload, by setting theHX-Locationresponse header.- Parameters:
route- the route to navigate to- Since:
- 1.10
- See Also:
-
hxLocation
Tells htmx to do a client-side redirect with navigation context, by setting theHX-Locationresponse header to its JSON form.The
HxLocationargument carries the context of the navigation, like the target to swap into or the swap style:c.hxLocation(new HxLocation(books).target("#main").swap("outerHTML"));A location without any context is sent as the plain path, the same as
hxLocation(String).- Parameters:
location- the location to navigate to, with its context- Since:
- 1.10
-
hxRedirect
Tells htmx to do a full-page redirect, by setting theHX-Redirectresponse header.- Parameters:
url- the location to redirect to- Since:
- 1.10
-
hxRedirect
Tells htmx to do a full-page redirect to a route, by setting theHX-Redirectresponse header.- Parameters:
route- the route to redirect to- Since:
- 1.10
-
hxRefresh
public void hxRefresh()Tells htmx to refresh the whole page, by setting theHX-Refreshresponse header.- Since:
- 1.10
-
hxPushUrl
Tells htmx to push a new URL into the browser history, by setting theHX-Push-Urlresponse header.- Parameters:
url- the URL to push- Since:
- 1.10
-
hxPushUrl
Tells htmx to push a route's URL into the browser history by setting theHX-Push-Urlresponse header.Since the URL is generated from the route, it will survive renaming and refactoring.
- Parameters:
route- the route whose URL to push- Since:
- 1.10
-
hxNoPushUrl
public void hxNoPushUrl()Tells htmx not to push a URL into the browser history for this response, by setting theHX-Push-Urlresponse header tofalse.This suppresses the history entry that an
hx-push-urlattribute or a boosted element would otherwise record.- Since:
- 1.10
- See Also:
-
hxReplaceUrl
Tells htmx to replace the current URL in the browser history, by setting theHX-Replace-Urlresponse header.- Parameters:
url- the replacement URL- Since:
- 1.10
-
hxReplaceUrl
Tells htmx to replace the current URL in the browser history with a route's URL, by setting theHX-Replace-Urlresponse header.- Parameters:
route- the route whose URL replaces the current one- Since:
- 1.10
-
hxNoReplaceUrl
public void hxNoReplaceUrl()Tells htmx not to replace the current URL in the browser history for this response, by setting theHX-Replace-Urlresponse header tofalse.This suppresses the URL replacement that an
hx-replace-urlattribute would otherwise perform.- Since:
- 1.10
- See Also:
-
hxRetarget
Tells htmx to swap the response into a different target than the triggering element's, by setting theHX-Retargetresponse header to a CSS selector.- Parameters:
cssSelector- the CSS selector of the new target- Since:
- 1.10
-
hxReswap
Tells htmx to change how the response is swapped in, by setting theHX-Reswapresponse header to anhx-swapvalue such asouterHTMLorbeforeend.- Parameters:
swapStyle- the swap style to use- Since:
- 1.10
-
hxReselect
Tells htmx to select only part of the response for swapping, by setting theHX-Reselectresponse header to a CSS selector.- Parameters:
cssSelector- the CSS selector to select from the response- Since:
- 1.10
-
hxTrigger
Triggers a client-side event as soon as the response is received, by adding it to theHX-Triggerresponse header.Calls accumulate: each one adds its event to the same header, so independent pieces of code can trigger their own events without overwriting each other. A single event without a payload travels as a plain event name; as soon as several events or a payload are involved, the header switches to htmx's JSON object form, where an event without a payload carries a
nulldetail. Triggering the same event again replaces its payload.- Parameters:
event- the name of the event to trigger- Since:
- 1.10
-
hxTrigger
Triggers a client-side event with a data payload as soon as the response is received, by adding it to theHX-Triggerresponse header.The payload is serialized to JSON with RIFE2's own
Jsonsupport, so records, beans, maps and collections all work without an extra dependency. Calls accumulate likehxTrigger(String).- Parameters:
event- the name of the event to triggerdata- the payload delivered as the event's detail- Since:
- 1.10
-
hxTriggerAfterSettle
Triggers a client-side event after the settle step, by adding it to theHX-Trigger-After-Settleresponse header.Calls accumulate like
hxTrigger(String), separately from the other trigger headers.- Parameters:
event- the name of the event to trigger- Since:
- 1.10
-
hxTriggerAfterSettle
Triggers a client-side event with a data payload after the settle step, by adding it to theHX-Trigger-After-Settleresponse header.Calls accumulate like
hxTrigger(String), separately from the other trigger headers.- Parameters:
event- the name of the event to triggerdata- the payload delivered as the event's detail- Since:
- 1.10
-
hxTriggerAfterSwap
Triggers a client-side event after the swap step, by adding it to theHX-Trigger-After-Swapresponse header.Calls accumulate like
hxTrigger(String), separately from the other trigger headers.- Parameters:
event- the name of the event to trigger- Since:
- 1.10
-
hxTriggerAfterSwap
Triggers a client-side event with a data payload after the swap step, by adding it to theHX-Trigger-After-Swapresponse header.Calls accumulate like
hxTrigger(String), separately from the other trigger headers.- Parameters:
event- the name of the event to triggerdata- the payload delivered as the event's detail- Since:
- 1.10
-
varyOn
Declares that the response depends on one or more request headers, by adding each to the response'sVaryheader so a cache keeps responses that differ on those headers apart.You should use this method whenever you shape the response from a request header that you read, such as branching on
isHxRequest()orisHxBoosted()to serve different content. The htmx accessors only read their headers and don't vary on their own, precisely so that reading a header for logging, or for a decision that doesn't change the output, never fragments a cache.printHtmxFragment(rife.template.Template, java.lang.String)declares its own variance, which means that this method is only needed when you do the branching yourself. Each name is added at most once per request, so that repeated calls don't have any additional effect.- Parameters:
headers- the request header names the response varies on- Since:
- 1.10
- See Also:
-