Home of: [Atelier "FUJIGURUMA"] >> [PageMixer hosted by SourceForge.net]

SEE "For Readers of English Version",
or Japanese version of this page

Forward control

This section explains how to customzie control forwarding with PageServlet.

You can skip this section if you have no interest to forward control to another page.

Overview

Class diagram

Class diagram in this section is shown below:

Class diagram
Class diagram (click for large figure)

Classes which you must define are colored, and other are already defined.

Class names

In this tutorial, abbreviated class names are used. Complete names are shown below.

Classes of PageMixer framework

NotationFull name
ConsumerContext jp.ne.dti.lares.foozy.pagemixer.mixer.ConsumerContext
ForwardCondition jp.ne.dti.lares.foozy.pagemixer.servlet.ForwardCondition
ForwardStrategy jp.ne.dti.lares.foozy.pagemixer.servlet.ForwardStrategy
PageServlet jp.ne.dti.lares.foozy.pagemixer.servlet.PageServlet
RequestKey jp.ne.dti.lares.foozy.pagemixer.servlet.RequestKey
SessionKey jp.ne.dti.lares.foozy.pagemixer.servlet.SessionKey

Tutorial specific classes

No tutorial specific class is explained in this section.

Purpose of customization

Sometime you may want to forward control from one Servlet to another. For example, you will want to forward control from member limited pages to login form page.

Separating the control forward logic from HTTP response renderring allows you to:

  1. reuse same logic in Servlets without programming,
  2. choose forwarding logic not only at compilation but also at configuration,
  3. and so on

Concretize ForwardCondition

PageMixer provides "ForwardStrategy" for customization of control forwarding.

But in fact, ForwardStrategy default implementation does not determine whether control should be forwarded to another Servlet. ForwardStrategy asks "ForwardCondition"s, which are registered to itself.

ForwardCondition has the method to accept inquiry whether control should be forwarded or not, and where if it should, as shown below.


public String forwards(ConsumerContext context)

Method signature of forwards()

This should return non-null value as forwarding destination when control should be forwarded, or return null otherwise. Sample implementation is shown below:


if(null == context.getValue(KEY_LOGIN)){
    context.setValue(KEY_LOGIN_REQUIRED, KEY_LOGIN_REQUIRED);
    return authPage_;
}

return null;

Concretization of forwarding determination

In this example, KEY_LOGIN and KEY_LOGIN_REQUIRED are instance of SessionKey to identify value which is set when user already login, and RequestKey to indicate whether user try to access member limited page or not.

You may also want to determine forwarding destination not at compiling but at configuration. In this example, it is held in authPage_.

ForwardCondition also provides setup method for initialization of classes derived from it, and defult implementation of it does nothing. Overriding example of it is shown below:


public void setup(HttpServlet servlet)
    throws ServletException //
{
    super.setup(servlet);

    ServletContext context = servlet.getServletContext();
    authPage_ = context.getInitParameter(INIT_PAGE_AUTH);
    if(null == authPage_){
        throw new ServletException(INIT_PAGE_AUTH);
    }
}

Overriding of setup

INIT_PAGE_AUTH has value to look up the context parameter, which is path of login(= authentication) page. So, you can forward control to login page if your custom ForwardCondition returns authPage_.

Please see API document for detail to concretize ForwardCondition and/or override ForwardStrategy.

Configuration

Parameters for base class

ForwardStrategy accepts Servet initialize parameter(s) shown below:

name description
forward.condition.N name of ForwardCondition implement class. "N" is 0 origin number. you can specify multiple ForwardConditions.

Parameter to use choosen class

To use your custom ForwardStrategy, you should specify "servlet.forwardStrategy" Servlet init-param in deployment descriptor as shown below.


<init-param>
  <param-name>
    servlet.forwardStrategy
  </param-name>
  <param-value>
    name of your custom ForwardStrategy
  </param-value>
</init-param>

Specify custom ForwardStrategy

To next section "Create 'Filter's"