5.3 JexlInspectionResultProcessor

JexlInspectionResultProcessor processes the inspection result and evaluates any expressions of the form ${...} using Apache Commons JEXL. It can be used to introduce declarative UI scripting into environments that lack their own expression language (i.e. JSP has an EL, Swing does not). For example:

<entity type="com.myapp.Person">
	<property name="pension" hidden="${!this.retired}"/>
</entity>

Arrays and collections are also supported:

<entity type="com.myapp.Person">
	<property name="pension" lookup="${this.arrayOfValues}"/>
</entity>

JexlInspectionResultProcessor would update this inspection result's hidden attribute based on evaluating the JEXL expression ${!this.retired} (where this refers to the instance of the Person being inspected). It could be used to show/hide the pension field in response to the retired checkbox being checked.

The JEXL expression language also supports branching statements. For example:

import org.metawidget.inspector.annotation.*;

public class ContactDialog {

	@UiAction
	@UiLabel( "${if ( this.readOnly ) 'Back'}" )
	public void cancel() { ... }
}

JexlInspectionResultProcessor would update the label of this action to be either 'Back' or default to 'Cancel', depending on whether the Contact was being edited. It is taken from the Swing Address Book sample (see Section 1.3.1, “Desktop Address Book”).

You can inject arbitary objects into the JEXL context either by subclassing and overriding JexlInspectionResultProcessor.createContext, or by using...

config.setInject( new PersonController() )

...or the equivalent via metawidget.xml...

<inject>
	<array>
		<instanceOf>com.myapp.PersonController</instanceOf>
	</array>
</inject>

Whereupon you can access the injected object through a JEXL expression such as:

${personController.all}