Table of Contents

Article

How to use Java expressions in a When directive or When JSP tag

Summary

A developer asks: Within the HTML code of a rule that inherits from the Rule-Stream class (such as a section rule or any of the HTML rules), I can use the When directive to invoke a when condition rule.

Within the When directive, however, I am un able to call a function rule,. such as:

{WHEN @PropertyHasValue(.pyLabel) }

That syntax will save, but fails during execution.  Why?  How do I accomplish the desired conditionalization?



 

Suggested Approach

Your attempt to call function in a when directive:

{WHEN @PropertyHasValue(.pyLabel) }

fails during execution because at runtime Process Commander searches for a when rule named @PropertyHasValue, and does not find any when rule with that name.

You can, however, use a Java expression within a when directive to accomplish the conditional you wish.  For example:

{When .pyLabel != ""}

Or, to display only the values of a Value List property only for those where the value is not "Test":

{Foreach .AStringList}
    {When $this != "Test"}
       {$this} <P>
    {/When}
{/ForEach}

Your Java expression can contain the standard Java operators such as !=, ||, &&, +, -, and == and parentheses for grouping.

When JavaServer Page tag

Starting with V42SP5, using JavaServer Pages (JSP) tags rather than directives is the recommended and default approach to writing stream-based rules.   When using JSP tags, the premise of the question is not strictly true.  You can specify:

<pega:when java=”com.pegarules.generated.LibraryName.functionName(parameters)” >

</pega:when>

-- though if a Java expression meets your requirement, avoid this complex approach.

Published November 10, 2005 — Updated November 10, 2005

Have a question? Get answers now.

Visit the Pega Support Community to ask questions, engage in discussions, and help others.