Adding actions to Screen widgets

Using data from a database or other source to build portions of your web page dynamically enables efficient and effective web page creation by freeing the screen's author from hardcoding values. To give widgets access to data sources and allow data preparation tools to fetch required input data, widget definitions include an actions element. Within the actions element, you may include directives to:

  • Read and set context variables
  • Make database calls directly
  • Call scripting languages such as BeanShell or Groovy
  • Call other OFBiz Services

Getting ready

Some initial preparation has to be done to add new actions, as follows:

  1. Open a Screen widget definition file and select a screen to add an action to.
  2. If your Screen widget definition does not have an actions element defined, add one.

How to do it...

Actions can be added by the following steps:

  1. Add one more actions element. Each action is either a directive instructing OFBiz to gather data directly and place that data in the screen's context, or a file location pointer to a script file.
  2. Close the actions element with an end tag (</actions>).
  3. Save the file.

Note

Note: The addition of actions to a screen definition is immediate. You do not need to restart OFBiz.

How it works...

The OFBiz screen handler invokes the actions declarations (in the order presented) to prepare data for merger with widgets declarations.

There's more...

To get Java properties file resources, add a directive similar to the following within the actions element of your widget definition:

<property-map resource="CommonUiLabels" map-name="uiLabelMap"
global="true"/>

To call a Groovy script, add an actions directive similar to the following:

<script location=
"component://myComponent/webapp/WEB-INF/actions/aGroovyScript.groovy"
/>

To make database calls directly from within a Screen widget's actions element, use the following actions element example—taken from the content Component's Screen widget definition for the Showforum screen—as your guide:

<actions>
<entity-condition list="forumMessages"
entity-name="ContentAssocViewTo">
<condition-list combine="and">
<condition-expr field-name="contentIdStart"
from-field="parameters.forumId"/>
<condition-list combine="or">
<condition-expr field-name="caContentAssocTypeId"
value="PUBLISH_LINK"/>
<condition-expr field-name="caContentAssocTypeId"
value="RESPONSE"/>
</condition-list>
</condition-list>
<order-by field-name="createdDate"/>
</entity-condition>
</actions>

You may even call an OFBiz Service from within an OFBiz widget. For example, the following XML snippet taken from a Screen widget definition (available out-of-the-box) calls a Service to assemble resources for a web page:

<actions>
<service service-name="getVisualThemeResources">
<field-map field-name="visualThemeId"/>
<field-map field-name="themeResources"
from-field="layoutSettings"/>
</service>
</actions>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.50.222