bean:call

Purpose

Calls a method on a bean.

Signature

bean:call(bean as object, method as xs:string, ...) as xs:any

Parameter

Name Description Type Use
bean The bean whose method is to be invoked. xs:string required 
method The name of a method to invoke. This must be a valid Java method identifier. xs:string required 
... An optional list of arguments to be passed to the method. xs:string optional 

Examples

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/2002/06/xhtml2"
  xmlns:pipeline="http://www.volantis.com/xmlns/marlin-pipeline"
  xmlns:bean="http://www.volantis.com/xmlns/2010/02/dci/bean">
  <head>
    <title>bean:create</title>
  </head>
  <body>
    <div>
      <pipeline:try>
        <pipeline:preferred>
          <!-- Create the bean. -->
          <bean:create
            class="com.volantis.openapi.pipeline.samples.beans.CalculatorBean"
            name="calculator">
            <bean:property name="initial" value="2"/>
          </bean:create>
          <!-- Perform some calculations, (2 + 10) * 3 and insert the result in the page. -->
          <pipeline:value-of expr="bean:call($calculator, 'add', 10)"/>
          <pipeline:value-of expr="bean:call($calculator, 'multiply', 3)"/> Total:
          <pipeline:value-of expr="bean:call($calculator, 'getTotal')"/>
        </pipeline:preferred>
        <!--
        ! At this point the scope containing the calculator bean and its variable has just
        ! been released so the bean is no longer alive and the variable no longer exists.
        !-->
        <pipeline:alternative> Oops </pipeline:alternative>
      </pipeline:try>
    </div>
  </body>
</html>

Where, com.volantis.openapi.pipeline.samples.beans.CalculatorBean contains the following code.

package com.volantis.openapi.pipeline.samples.beans;
public class CalculatorBean {
  private int total;
  public void setInitial(int initial) {
    total = initial;
  }
  public void add(int n) {
    total += n;
  }
  public void clear() {
    total = 0;
  }
  public void multiply(int n) {
    total = total * n;
  }
  public int getTotal() {
    return total;
  }
}
Note:

Java beans must be compiled with JDK version 1.5.0_x.

Note:

You need to ensure that beans are in your CLASSPATH.

Related topics