You can use the atg.integrations.MapRPCDroplet
servlet bean to execute RPC commands in JavaServer Pages. This servlet bean executes a command and, depending on whether the command is executed successfully, renders either its output
open parameter or its error
open parameter. If the command is executed successfully, the result
output parameter is set to the result of the command, and the output
open parameter is rendered. If an exception is thrown, the exception
output parameter is set to the exception, and the error
open parameter is rendered.
The command
input parameter takes an object that implements the atg.integrations.Command
interface. The inputParameters
parameter supplies the inputs to the command as a java.util.Map
of parameter name/value pairs.
As an alternative to specifying these values in pages, MapRPCDroplet
has command
and inputParameters
properties that you can use to specify these values in the servlet bean’s properties file. Note, however, that you cannot specify the same parameter both in the properties file and in a page. If you do this, MapRPCDroplet
throws a ServletException
.
MapRPCDroplet
also takes an inputParameterNames
parameter that you can use to specify the input names as a list of page parameters, and then use those page parameters to specify the input values. For example:
<dsp:param name="inputParameterNames" value="first_name,age"/>
<dsp:param name="first_name" value="Bill"/>
<dsp:param name="age" value="43"/>
You cannot include both the inputParameters
and the inputParameterNames
parameter in the same page, or include inputParameterNames
in the page if inputParameters
is specified in the servlet bean’s properties file.
However, there is a way you can specify default values for the command parameters in the servlet bean’s properties file, and then optionally override these values in pages. To do this:
Use the
inputParameters
property to specify the command parameters and their default values.In your pages, define page parameters with the same names as the command parameters.
The values specified for the page parameters override the values in the properties file, and are used when the command is invoked. If a command parameter has no corresponding page parameter, the default value from the properties file is used.
Input Parameters
command
The command to execute. Must be an instance of a class that implements theatg.integrations.Command
interface. This parameter can either be defined in a page or by setting thecommand
property of the servlet bean, but it cannot be defined both ways.
inputParameters
The inputs to pass to the command, supplied as ajava.util.Map
of parameter name/value pairs. This parameter can either be defined in a page or by setting theinputParameters
property of this servlet bean, but it cannot be defined both ways.
inputParameterNames
A comma-separated list of command input parameter names. Each name defines a page parameter whose name and value (specified in the page) are used to supply one of the inputs to the command.
parameter names
Page parameters that correspond to the names of command input parameters specified ininputParameterNames
.
Output Parameters
result
The result object from the command, if the execution is successful.
exception
The exception thrown by the command, if the execution is unsuccessful.
Open Parameters
output
Rendered if the command is executed successfully.
error
Rendered if the command throws an exception.
Example
The following example uses inputParameterNames
to create a UserId
page parameter, and then sets its value to the value of a profile ID. This parameter name/value pair is passed as an input to the command. Depending on whether the command is executed successfully, Dynamo renders either the output
open parameter or the error
open parameter.
<dsp:droplet bean="/atg/integrations/MapRPCDroplet">
<dsp:param name="command"
value="bean:/atg/integrations/jdbc/QueryForUser"/>
<dsp:param name="inputParameterNames" value="UserId"/>
<dsp:param name="UserId" value="bean:Profile.Id"/>
<dsp:oparam name="output">
<p>The user's email address is:
<dsp:valueof param="result.emailAddress"/>
</dsp:oparam>
<dsp:oparam name="error">
<p>Unable to execute query. The following exceptions occurred:
<dsp:valueof param="exception"/>
</dsp:oparam>
</dsp:droplet>