bean:create

Purpose

Creates a Java bean object. The operation is responsible for creating, initializing, and releasing the bean when it is not longer needed.

Contained by

Contains

Attributes

Attribute Description Type Default Options Use
class The name of a Java bean class to instantiate. xs:string     required 
name The name of a variable which will be created to reference the bean. xs:string   required 

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