View source | Discuss this page | Page history | Printable version   
Toolbox
Main Page
Upload file
What links here
Recent changes
Help

PDF Books
Add page
Show collection (0 pages)
Collections help

Search

How to create a callout that extends from another callout

Contents

Introduction

This howto discusses how to implement a callout that extends from another callout. This howto only explain the main important elements needed for the new feature. More details about callouts can be found in the How to create a Callout howto.

Bulbgraph.png   This feature is available from version 3.0PR16Q4

Example Module

This howto is supported by an example module which shows examples of the code shown and discussed.

The code of the example module can be downloaded from this public mercurial repository: org.openbravo.client.application.examples.

Defining callouts

It are going to show two callouts. One of them is the parent callout and the other one is the child callout.In this example, these two callouts are working in 'Assets' window.

Defining Parent Callout

The following example follows this guide to implement the callout. The example shows a callout that edits value of the 'Name' field.

 
package org.openbravo.client.application.examples.callouts;
 
import javax.servlet.ServletException;
 
import org.openbravo.erpCommon.ad_callouts.SimpleCallout;
 
public class OBEXAPP_Assets_Name extends SimpleCallout {
 
  @Override
  protected void execute(CalloutInfo info) throws ServletException {
    // get value of field name and update value
    final String name = info.getStringParameter("inpname");
    info.addResult("inpname", name + "_edited_by_OBEXAPP_Assets_Name");
  }
 
}

As you can see the callout gets the value of 'Name' field and concatenates the following string: '_edited_by_OBEXAPP_Assets_Name'.

Defining Child Callout

This example callout extends from the parent callout that is defined above. Combo example is explained in next section.

 
package org.openbravo.client.application.examples.callouts;
 
import javax.servlet.ServletException;
 
public class OBEXAPP_Assets_Desc extends OBEXAPP_Assets_Name {
 
  @Override
  protected void execute(CalloutInfo info) throws ServletException {
 
    // It is possible to perform any operation before running the parent callout.
    String originalName = info.getStringParameter("inpname");
 
    // Combo example. Added three currencies to currency combo.
    ............
 
    // Then parent callout is executed
    super.execute(info);
 
    // Finally it is possible to execute this callout taking into account last changes.
    String name = info.getStringParameter("inpname");
 
    if (originalName.equals(name)) {
      info.addResult("inpdescription", name + ". Not works as expected.");
      log4j.info("Extends a callout not works properly.");
    } else {
      info.addResult("inpdescription", name + ". Extends a callout works as expected.");
      log4j.info("Feature 'Extends a Callout' works as expected");
 
      // Now it is possible to update the 'name' field again and the value will be overwritten
      info.addResult("inpname", name + "_updated");
    }
  }
}

First of all, OBEXAPP_Assets_Desc callout extends from OBEXAPP_Assets_Name. In this situation, you should take into account 3 sections in this callout:

 
    // It is possible to perform any operation before running the parent callout.
    String originalName = info.getStringParameter("inpname");
 
    // Combo example. Added three currencies to currency combo.
    ............
 
    // Then parent callout is executed
    super.execute(info);
 
    String name = info.getStringParameter("inpname");
 
    if (originalName.equals(name)) {
      info.addResult("inpdescription", name + ". Not works as expected.");
      log4j.info("Extends a callout not works properly.");
    } else {
      info.addResult("inpdescription", name + ". Extends a callout works as expected.");
      log4j.info("Feature 'Extends a Callout' works as expected");
 
      // Now it is possible to update the 'name' field again and the value will be overwritten
      info.addResult("inpname", name + "_updated");
    }

Working with combos

First of all, the OBEXAPP_Assets_Desc callout builds a currency combo. This combo is populated with 3 currencies and one of them is selected.

    ............
 
    // Combo example. Added three currencies to currency combo.
    info.addSelect("inpcCurrencyId");
    // USD currency is selected.
    info.addSelectResult("100", "USD", true);
    info.addSelectResult("102", "EUR", false);
    info.addSelectResult("103", "DEM", false);
    info.endSelect();
 
    ............

Then, it is removed a currency and selected another one in the parent callout called OBEXAPP_Assets_Name.

    ............
 
    // Combo example. Removed USD currency from combo and select DEM currency.
    info.addSelect("inpcCurrencyId");
    info.removeSelectResult("100");
    info.addSelectResult("103", "DEM", true);
    info.endSelect();
 
    ............

In this screenshot you can see how currency combo is displayed.

Bulbgraph.png  

The DEM currency is selected and USD currency has been removed.

Combo-callout.png

Using getStringParameter method

This method is used in callouts to get values of any field of the window.(e.g. value of name field in Assets window).

Now, with the inclusion of this project this method takes into account if a parent callout modified a value. If a value was modified, "getStringParameter()" method returns value modified by parent callout. If not, "getStringParameter()" method returns the initial value of the parameter.

Retrieved from "http://wiki.openbravo.com/wiki/How_to_create_a_callout_that_extends_from_another_callout"

This page has been accessed 216 times. This page was last modified on 21 September 2016, at 12:39. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.