Show
all
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.
Introduction
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.
JSP equivalent
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.
Complete
syntax
In the syntax presentations below:
- Square bracket characters
[
and ]
define optional parts of the directive. Do not type the
brackets.
- Curly brace characters
{
and }
mark
the start and end of the directive.
- Replace any text in italics with your choice of value of that
type.
Two syntax options are available:
Option 1
{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]}
Option 2
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. %}
Examples
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}
Examples — Using inline
Java and PublicAPI
Directives