Screen Widget Actions in Java

From Opentaps Wiki
Jump to navigationJump to search

As part of opentaps 1.4, we are introducing Java actions for the ofbiz screen widget based on OFBIZ-44. This allows you to write the data preparation logic of a screen in Java instead of scripting languages.

To use this feature, in your screen widget XML, use the java directive to invoke your Java class and method:

<screen name="findAndListInvoices">
         <java location="com.opensourcestrategies.financials.invoice.InvoiceActions" invoke="findInvoices"/>

Your Java method must be a static method which accepts a Map of the context as a parameter:

public static void findInvoices(Map<String, Object> context) throws GeneralException, ParseException {

The context contains environment variables as well as parameters for your screen. Opentaps has an which takes the Map and allows you to obtain environment variables from it and put values back into the context for your screen:

final ActionContext ac = new ActionContext(context);
// ... for example
String invoiceTypeId = ac.getString("invoiceTypeId");
// ... for example
ac.put("processingStatuses", processingStatusList);