JSP Controls Tag Library: The Component Lifecycle
Forwarding to composite page
The optional approach to reload a component in non-Ajax mode is to perform a server-side forward to a composite page:
It works similar to redirection, but instead of forcing the browser to load the composite page with a separate HTTP request, the component performs an in-server forward to the composite page location. The composite page is returned immediately in response to the input event.
To use forwarding instead of redirection you have to set "redirect" attribute of Reload tag to "false"; its default value is "true".
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib uri="/WEB-INF/lib/jspcontrols.tld" prefix="jc" %> <span id="LoginComponent"> <%-- Accept phase --%> <jc:handler event="login"> ... </jc:handler> <jc:handler event="logout"> ... </jc:handler> <jc:reload redirect="false"/> <%-- Render phase --%> <jc:prerender> ... </jc:prerender> <jc:render view="notloggedin"> ... </jc:render> <jc:render view="loggedin"> ... </jc:render> </span>
Forwarding is frowned upon as the means of page reloading. It is the source of double submit problem and other issues related to Back and Refresh buttons. Forwarding does not require the component to retain state between requests. This seems like a benefit because it allows to build applications that use less memory from the session object. This approach works until a user reloads a composite page manually. Because a component may not have saved its state, it would render itself improperly.
Another benefit of forwarding versus redirection is saving on the roundtrip to the browser and back. The roundtrip does not seem like a problem, neither time-wise, nor traffic-wise, considering its benefits for usability and overall robustness.
JSP Controls Tag Library is designed to support stateful components, therefore it strongly discourages in-server forwarding.
It is possible to combine benefits of redirection (avoiding Back button issues) and benefits of forwarding (preventing the roundtrip to the browser) using In-place updating technique in a browser that supports Javascript and XMLHTTPRequest. In this case the component is activated asynchronously. A view fragment is returned immediately in response to input request, and is inserted into composite page.