JSP Controls Tag Library
 

JSP Controls Tag Library: The Component Lifecycle

Redirecting to composite page

The standard approach to proceed from accept phase to render phase in non-Ajax mode is to redirect to composite page:

Redirect to composite page

When the composite page is loaded, its address is saved by Prerender tag so it could have been used later by Reload tag as redirect destination. In case of the Login Component, the redirection target is "index.jsp" page. Unless you need to redirect to another page after accept phase is finised, you do not need to care about how redirect destination is resolved. All you need to do is to specify Reload tag after the Handler tags when you finished processing input data:

<%@ 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/>

  <%-- Render phase --%>

  <jc:prerender> ... </jc:prerender>
  <jc:render view="notloggedin"> ... </jc:render>
  <jc:render view="loggedin"> ... </jc:render>
</span>

After browser is redirected, it starts to load the composite page with a "clean" GET request. From this point the page load sequence repeats and finishes the accept/render cycle.

Neither the composite page nor other components (if any) realised that Login Component was activated. All they know is that the composite page was forced to reload. Voila, a portlet-like component with no central controller and no portlet API.

Notice, that if composite page contains other components that depend on the same state as Login Component, they will have rerendered themselves appropriately. This is how indirect component communication works.

Pros and Cons of redirection

Redirection is the default mechanism of switching from accept phase to render phase in non-Ajax mode. This approach employs Redirect-After-Post pattern that unties initial data submission from server response, preventing from implicit resubmits and Back button issues.

The downsides of redirection is a roundrip to the browser and back, and the requirement for a component to retain state between requests. Components are supposed to be stateful, so the latter requirement seems sensible. If keeping state between requests is impossible, the Library allows to forward to composite page instead of redirecting to it.