Formatting of input properties to views

For Web requests, when controller command completes, it returns the name of a view that should be executed. This view may require that several input properties get passed to it.

There can be three sources for these input parameters:

  • Default properties that are stored in the PROPERTIES column of the CMDREG table
  • Default properties from the Struts configuration files
  • Input properties from the URL

For a redirect response, the input properties to a view can be formatted using either of these techniques:

  • Flattening a query string to support URL redirection
  • Dealing with a limit on the length of the redirect URL

For forward view commands, the topic of enumeration of input parameters and setting them as attributes in the HttpServletRequestObject is examined.

Flattening input parameters into a query string for HttpRedirectView

All input parameters that are passed to a redirect view command are flattened into a query string for URL redirection. For example, suppose that the input to the redirect view command contains the following properties:


URL = "MyView?p1=v1&p2=v2";
ip1 = "iv1";   // input to original controller command 
ip2 = "iv2" ;  // input to original controller command
op1 = "ov1";
op2 = "ov2";

Based upon the preceding input parameters, the final URL is


MyView?p1=v1&p2=v2&ip1=iv1&ip2=iv2&op1=ov1&op2=ov2

Note that if the command is to use SSL, then the parameters are encrypted and the final URL appears as


MyView?krypto=encrypted_value_of"p1=v1&p2=v2&ip1=iv1&ip2=iv2&op1=ov1&op2=ov2"

Handling a limited length redirect URL

By default, all input parameters to the controller command are propagated to the redirect view command. If there is a limit on the number of characters in the redirect URL, this may cause a problem. An example of when the length may be limited is if the client is using the Internet Explorer browser. For this browser, the URL cannot exceed 2083 bytes. If the URL does exceed this limit, the URL gets truncated. As such, you can encounter a problem if there are a large number of input parameters, or if you are using encryption, because an encrypted string is typically two to three times longer than a string that is not encrypted.

There are two approaches for handling a limited length redirect URL:

  1. Override the getViewInputProperties method in the controller command to return only the sets of parameters that are required to be passed to the redirect response.
  2. Use a specified special character in the URL parameters to indicate which parameters can be removed from the input parameter string.

To demonstrate each of the preceding approaches, consider the following set of input parameters to the controller command:


URL="MyView"; 
// All of the following are inputs to the original controller command.
ip1="ipv1";
ip2="ipv2";
ip3="ipv3";
iq1="iqv1";
iq2="iqv2";
ir1="ipr1";
ir2="ipr2";
is="isv";

If you are overriding the getViewInputProperties method, the new method can be written so that only the following parameters are passed to the view command:


ir2="ipr2";
is="isv";

Using the second approach, the view command can be invoked using special parameters to indicate that certain input parameters should be removed. For example, you can achieve the same result by specifying the following as the URL parameter:


URL="MyView?ip*=&iq*=&ir1="

This URL parameter instructs the WebSphere Commerce runtime framework of the following:

  • The ip*= specification means that all parameters whose names start with ip should be removed.
  • The iq*= specification means that all parameters whose names start with iq should be removed.
  • The ir1= specification means that the ir1 parameter should be removed.

Setting attributes in the HttpServletRequest object for HttpForwardView

The default HttpForwardViewCommandImpl enumerates all of the parameters passed to the command and sets them as attributes in the HttpServletRequest object.

For example, suppose that the requestProperties object passed to the forward view command contains the following parameters:


p1="pv1";
p2="pv2";
p3=pv3;   // pv3 is an object

Then the following attributes are passed to the JSP page using the request.setAttribute() method.


request.setAttribute("p1", "pv1");
request.setAttribute("p2", "pv2");
request.setAttribute("p3", pv3);
request.setAttribute("RequestProperties", requestProperties);
request.setAttribute("CommandContext", commandContext);

Where:

requestProperties
The TypedProperty object that is passed to the command.
commandContext
The command context object that is passed to the command.
p1, p2, p3
The parameters defined in the requestProperties object.