Java directive |
Use the Java directive to insert stand-alone Java source code or an inline expression into the Java generated to build an HTML stream for display, HTML stream for correspondence, or XML stream for SOAP.
In this example, the Java directive causes the resulting HTML to contain the current requestor's name.
{JAVA}
appendString (pega_rules_default.GetRequestorName());
{/JAVA}
The inserted Java can use the Pega.BuildStream
and Pega.Activity
public methods.
Use the normal JSP brackets <% and %> to surround Java statements in a JSP stream. For an expression that returns a value, use the <%= and %> brackets. No pega JSP tag is required.
In the syntax presentations below:
[
and ]
define optional parts of the directive. Do not type the brackets.{
and }
mark the start and end of the directive.Two syntax options are available:
{JAVA [comments]}
Insert your Java here. It appears exactly as you enter it here in the generated Java code.
{/JAVA [comments]}
The ENDJAVA
element is an alternative to the {/JAVA} tag.
{ENDJAVA [comments]}
As a shortcut, or for an expression to be embedded within another directive, or embedded in an HTML element tag, use this syntax:
{% Insert your Java here. %}
In this example, the Java directive causes the HTML to display an anchor link at runtime when a user has a SysAdmin4
role, and does something else otherwise.
Use the backslash escape character \ to embed HTML text within a Java string.
{JAVA}
if (PegaRulesRequestor.haveRoleSecurity("Pega-RULES:SysAdmin4"))
{
appendString("<LI><A
HREF=\"/SERVLET/prServlet?pyStream=EPROADMIN\"
TARGET=\"SESSION\" TITLE=\"Click here to access the System Administration workspace\">System Administration</A></TD>");
}
else
{
appendString("<LI><A class=\"anchorToBeLarge\">System Administration</TD>");
}
{/JAVA}