All of the parameter values we have seen so far have been either Strings, or else open parameters (whose values, by the way, are of type Servlet). It is possible for parameters to be assigned values that are of other types, such as Vectors, arrays, or any other Java type. We have already seen a way that arbitrary objects can be assigned to parameters through the DynamoHttpServletRequest.setParameter() method.

Arbitrary objects can also be assigned to parameter values by attaching the parameter values to object properties through JSP files. For example:

<dsp:droplet name="/test/counter">
  <dsp:param bean="/test/Person.age" name="maxcount"/>
  <dsp:oparam name="lineformat">
    <li>This is number <dsp:valueof param="number"/>
  </dsp:oparam>
</dsp:droplet>

Here the parameter maxcount has been assigned a value from the age property of the /test/person component. Primitive types such as int, float, short, are converted automatically to the corresponding Java object types Integer, Float, Short, etc. Because the age property is of type int, the resulting property value will be of type Integer.

Parameters with arbitrary object values may be displayed using the dsp:valueof or paramvalue=... constructs, just as they would be for String parameter values. You can also display arbitrary object values within an ATG Servlet Bean by calling DynamoHttpServletRequest.serviceParameter().

AN ATG Servlet Bean will often need to obtain the value of an object parameter without actually displaying that parameter. For example, an ATG Servlet Bean might use the maxcount parameter to specify some sort of limit.

The HttpServletRequest.getParameter() method is not suitable for this because it can only access parameters that are of type String. To access arbitrary objects, you’ll need to use another method from DynamoHttpServletRequest called getObjectParameter(). For example:

public void service (DynamoHttpServletRequest request,
                     DynamoHttpServletResponse response)
     throws ServletException, IOException
{
  ServletOutputStream out = response.getOutputStream ();

  int maxcount = 0;
  Object maxcountval = request.getObjectParameter ("maxcount");
  if (maxcountval instanceof Integer)
    maxcount = ((Integer) maxcountval).intValue ();

  for (int i = 0; i < maxcount; i++) {
    request.setParameter ("number", new Integer (i));
    request.serviceParameter ("lineformat", request, response);
  }
}

In this example, the maxcount parameter, assigned to an integer property, is used to specify the upper bound for counting.

 
loading table of contents...