Version 4.10.0

hirondelle.web4j.action
Class ResponsePage

Object
  extended by hirondelle.web4j.action.ResponsePage

public final class ResponsePage
extends Object

Response page served to the user at the end of an Action.

Identifies the page as a resource. Does not include its content, but is rather a reference to the page.

The Controller will either redirect or forward to the resource identified by toString(), according to the value of getIsRedirect(). The default value of getIsRedirect() varies according to constructor:

These defaults are almost always the desired values. They can be changed, if necessary, by calling setIsRedirect(java.lang.Boolean). It's important to note that that method returns a brand new object - it doesn't change the state of an existing object.

See the forward-versus-redirect topic on javapractices.com for more information.


Constructor Summary
ResponsePage(String aURL)
          Constructor for a non-templated response.
ResponsePage(String aJsp, Class<?> aClass)
          Constructor for a non-templated response located under /WEB-INF/.
ResponsePage(String aTitle, String aBodyJsp, Class aRepresentativeClass)
          Constructor which uses the WEB4J template mechanism, with a conventional template.
ResponsePage(String aTitle, String aBodyJsp, String aTemplateURL)
          Constructor which uses the WEB4J template mechanism.
ResponsePage(String aTitle, String aBodyJsp, String aTemplateURL, Class<?> aClass)
          Constructor which uses the WEB4J template mechanism.
 
Method Summary
 ResponsePage appendQueryParam(String aParamName, String aParamValue)
          Append a query parameter to the URL of a ResponsePage.
 boolean equals(Object aThat)
           
 Boolean getIsRedirect()
          See class comment.
 Boolean hasBinaryData()
          Return true only if withBinaryData() was called.
 int hashCode()
           
 ResponsePage setIsRedirect(Boolean aValue)
          Return a new ResponsePage, having the specified forward/redirect behavior.
 String toString()
          Return the URL passed to the constructor, with any query parameters added by appendQueryParam(java.lang.String, java.lang.String) appended on the end.
static ResponsePage withBinaryData()
          Factory method for binary responses.
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ResponsePage

public ResponsePage(String aTitle,
                    String aBodyJsp,
                    String aTemplateURL)
Constructor which uses the WEB4J template mechanism.

Parameters:
aTitle - text of the <TITLE> tag to be presented in the template page ; appended to aTemplateURL as a query parameter
aBodyJsp - body of the templated page, where most of the content of interest lies ; appended to aTemplateURL as a query parameter
aTemplateURL - identifies the templated page which dynamically includes aBodyJsp in its content. Some applications will have only a single template for the entire application.

ResponsePage

public ResponsePage(String aTitle,
                    String aBodyJsp,
                    Class aRepresentativeClass)
Constructor which uses the WEB4J template mechanism, with a conventional template.

As in ResponsePage(String, String, String, Class), but with the template URL taking the conventional value of '../Template.jsp'.


ResponsePage

public ResponsePage(String aTitle,
                    String aBodyJsp,
                    String aTemplateURL,
                    Class<?> aClass)
Constructor which uses the WEB4J template mechanism.

This constructor allows for an unusual but useful policy : placing JSPs in the same directory as related code, under WEB-INF/classes, instead of under the document root of the application. Such a style is beneficial since it allows all (or nearly all) items related to a given feature to be placed in the same directory - JSPs, Action, Model Objects, Data Access Objects, and .sql files. This is the recommended style. It allows package-by-feature.

Parameters:
aTitle - text of the <TITLE> tag to be presented in the template page ; appended to aTemplateURL as a query parameter
aBodyJsp - body of the templated page, where most of the content of interest lies ; appended to aTemplateURL as a query parameter
aTemplateURL - identifies the templated page which dynamically includes aBodyJsp in its content
aClass - class literal of any java class related to the given feature; the package of this class will be used to construct the 'real' path to aBodyJsp, as in 'WEB-INF/classes/<package-as-directory-path>/<aBodyJsp>'. These paths are completely internal, are known only to the Controller, and are never visible to the user in the URL.

ResponsePage

public ResponsePage(String aURL)
Constructor for a non-templated response.

This constructor does not use the WEB4J template mechanism. This constructor is used both for response pages that require a redirect, and for serving pages that do not use the templating mechanism.

aURL identifies the resource which will be used by an Action as its destination page. Example values for aURL :

This constructor returns a redirect. If a forward is desired, call setIsRedirect(Boolean).


ResponsePage

public ResponsePage(String aJsp,
                    Class<?> aClass)
Constructor for a non-templated response located under /WEB-INF/.

This constructor allows for an unusual but useful policy : placing JSPs in the same directory as related code, under WEB-INF/classes, instead of under the document root of the application. Such a style is beneficial since it allows all (or nearly all) items related to a given feature to be placed in the same directory - JSPs, Action, Model Objects, Data Access Objects, and .sql files. This is the recommended style. It allows package-by-feature.

This constructor defaults the response to a forward operation.

Parameters:
aJsp - simple name of a JSP, as in 'view.jsp'
aClass - class literal of any java class in the same package as the given JSP. The package of this class will be used to construct the 'real' path to the JSP, as in
WEB-INF/classes/<package-as-directory-path>/<aJsp>
These paths are completely internal, are known only to the Controller, and are never visible to the user in the URL.
Method Detail

withBinaryData

public static ResponsePage withBinaryData()
Factory method for binary responses. An example of a binary reponse is serving a report in .pdf format.

With such ResponsePages, the normal templating mechanism is not available (since it is based on text), and no forward/redirect is performed by the Controller. In essence, the Action becomes entirely responsible for generating the response.

When serving a binary response, your Action will typically :


hasBinaryData

public Boolean hasBinaryData()
Return true only if withBinaryData() was called.


toString

public String toString()
Return the URL passed to the constructor, with any query parameters added by appendQueryParam(java.lang.String, java.lang.String) appended on the end.

Overrides:
toString in class Object

getIsRedirect

public Boolean getIsRedirect()
See class comment.


setIsRedirect

public ResponsePage setIsRedirect(Boolean aValue)
Return a new ResponsePage, having the specified forward/redirect behavior. See class comment.

This method returns a new ResponsePage having the updated URL. (This will ensure that ResponsePage objects are immutable.)


appendQueryParam

public ResponsePage appendQueryParam(String aParamName,
                                     String aParamValue)
Append a query parameter to the URL of a ResponsePage.

This method returns a new ResponsePage having the updated URL. (This will ensure that ResponsePage objects are immutable.)

This method uses WebUtil.setQueryParam(java.lang.String, java.lang.String, java.lang.String).


equals

public boolean equals(Object aThat)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

Version 4.10.0

Copyright Hirondelle Systems. Published October 19, 2013 - User Guide - All Docs.