Expression Language Extensions

Web Center provides a means to evaluate functions in expressions. The functions may have one parameter only.

Functions can for example be used to:

  • Check if an attribute exists for a given entry.

  • Check if an attribute has a specific value for a given entry.

  • Check if all attribute values of a given entry match a regular expression.

The tags for defining and assigning expression functions are part of the expression tag library which must be declared in JSP files with the include direction

<%@ taglib uri="http://www.siemens.com/directory/webManager/expr"
           prefix="expr" %>

We recommend using the prefix “expr” but you may choose any other unique prefix.

Defining Functions

Attribute Exists

The tag “attributeExists” generates a function that checks if an attribute exists.

The following example defines a function with name “isFinished” which checks if the workflow end time is set.

<expr:method name="isFinished">
    <expr:attributeExists name="wfEndTime"/>
</expr:method>

Attribute Contains

The tag “attributeContains” generates a function that checks if an attribute contains a specific value.

The following example defines a function with name “isFunctionalUser” which checks if one of the values of attribute “objectClass” is “dxrFunctionalUser”. The check is done case-insensitive.

<expr:method name="isFunctionalUser">
    <expr:attributeContains
        name="objectClass"
        value="dxrFunctionalUser"
        caseIgnore="true"/>
</expr:method>

Attribute Matches

The tag “attributeMatches” generates a function that checks if one or all values of an attribute match a regular expression.

The following example defines a function with name “isContractorOrSupplier” which checks if one of the values of attribute “employeeType” is “Customer” or “Supplier”. The check is done case-insensitive.

<expr:method name="isContractorOrSupplier">
    <expr:attributeMatches
        name="employeeType"
        expression="Contractor|Supplier"
        caseIgnore="true"
        all="false"/>
</expr:method>

Assigning the Functions to a Scoped Variable

We must assign functions to a scoped variable.This provides us with a handle to invoke the functions in expressions later on.We enclose the “method” tags in a “methods” tag and pass the variable’s name and scope as tag attributes.

The following example assigns the three functions defined above to the session-scoped variable with name “apply”.

<expr:methods var="apply" scope="session">
    <expr:method name="isFinished">
        ...
    </expr:method>
    <expr:method name="isFunctionalUser">
        ...
    </expr:method>
    <expr:method name="isContractorOrSupplier">
        ...
    </expr:method>
</expr:methods>

We can now invoke the functions for example with “sessionScope.apply.isFinished” or simply “apply.isFunctionalUser” if there’s no variable with name “apply” defined in page or request scope.

The functions access the database which means they need a valid session.That’s why we put them into session scope.

A convenient place to add the code to is the initSession.jsp in folder WEB-INF/jsp/controller/utils. The JSP is called once for each session.

Using the Functions

The functions can be used in expressions after they have been assigned to a scoped variable.The function argument must be passed in square brackets [].The argument can be a fixed string enclosed in single quotes, or any scoped variable.

The standard Web Center application uses functions only for menu selectors.But you can use them in expressions anywhere else.

Menu Selectors

The following extract from file WEB-INF/config/identity/menu-defs.xml shows how a function is used to define a menu selector with name “notFunctionalUser” that applies if the selected user is not a functional user.

<definition name=".menuSelectors">
  <put name="notFunctionalUser"
    value="${not apply.isFunctionalUser
           [sessionScope['com.siemens.webMgr.selectedUser']]}"/>
</definition>

The menu selector is used later on in the same file to disable some menu items for functional users.

JSP Pages

This section gives some examples for using functions in expressions within JSP pages.

First, we store the logged-in user and the selected workflow item in page-scoped variables just for convenience:

<c:set var="loginUser"
       value="${sessionScope['com.siemens.webMgr.loginDN']}"/>
<c:set var="selectedWorkflowItem"
       value="${sessionScope['com.siemens.webMgr.selectedWorkflowItem']}"/>

Now, let’s check if the logged-in user is a functional user:

<c:choose>
    <c:when test="${apply.isFunctionalUser[loginUser]}">
        <%-- is a functional user --%>
    </c:when>
    <c:otherwise>
        <%-- is not a functional user --%>
    </c:otherwise>
</c:choose>

Next, we check if the logged-in user is a contractor or supplier, and store the result in a page-scoped variable:

<c:set var="selectedUserIsContractorOrSupplier"
       value="${apply.isContractorOrSupplier[loginUser]}"/>

Finally, we check if the selected workflow item is already finished:

<c:if test="${apply.isFinished[selectedWorkflowItem]}">
    <%-- is finished --%>
</c:if>