Thursday, December 12, 2013

Sapphire 0.7 : New EL Functions and Properties

Many new functions have been added to the expression language.

Absolute

Returns the absolute path of a value for properties with a RelativePathService.

${ Path.Absolute }
Content

Returns the content of a value or a transient. For value properties, the default is taken into account, if applicable.

${ PurchaseOrder.FulfillmentDate.Content }
Enabled

Returns the enablement of a property.

${ PurchaseOrder.FulfillmentDate.Enabled }

In the context of a property editor, Enabled function can also be called with zero arguments. This accesses the enablement of the property editor part.

<property-editor>
    <property>FormLoginPage</property>
    <visible-when>${ Enabled() }</visible-when>
</property-editor>
EndsWith

Tests if a string ends with the specified suffix.

${ Path.EndsWith( ".png" ) }
Fragment

Returns a fragment of a string. The fragment starts at the index specified by the second argument and extends to the character before the index specified by the third argument. The length of the fragment is end index minus start index.

  • A negative start index is normalized to zero.
  • A start index exceeding the length of the input is normalized to the length of the input.
  • An end index exceeding the length of the input is normalized to the length of the input.
  • An end index that is smaller than the start index is normalized to the start index.
${ Value.Fragment( 3, 6 ) }
${ Fragment( "abcdef", 0, 3 ) }
Head

Returns a fragment of a string starting at the beginning and not exceeding the specified length.

  • A negative fragment length is normalized to zero.
  • A fragment length exceeding the length of the input is normalized to the length of the input.
${ Value.Head( 3 ) }
${ Head( "abcdef", 3 ) }
Index

Determines the index of a model element within its parent list.

${ This.Index }
Matches

Determines whether a string matches a regular expression. The full semantics are specified by Java's String.matches() function.

${ Entity.Name.Matches( "[a-z][a-z0-9]*" ) }
Message

Returns the message from a validation result.

${ PurchaseOrder.FulfillmentDate.Validation.Message }
Parent

Returns the parent of the given part. An implementation of this function for model elements was added in an earlier release.

${ Part.Parent.Validation.Severity }
${ Part.Parent.Parent.Validation.Severity }
Part

Returns the context part.

${ Part.Validation.Severity }
Severity

Returns the severity of a validation result.

${ PurchaseOrder.FulfillmentDate.Validation.Severity }
Size

Determines the size of a collection, a map, an array or a string.

${ PurchaseOrder.Entries.Size }
${ PurchaseOrder.BillingInformation.Name.Size }
${ Size( "abcdef" ) }
StartsWith

Tests if a string starts with the specified prefix.

${ Path.StartsWith( ".." ) }
State Function

Returns the root element of editor page's persistent state, allowing access to various state properties. This is particularly useful when the persistent state is extended with custom properties wired to custom actions, as it allows any EL-enabled facility to integrate with the custom state property.

In the following example, a custom state property is used to control whether content outline node label for an item in the catalog sample should include the manufacturer.

<node-factory>
    <property>Items</property>
    <case>
        <label>
        ${ 
             Name == null 
             ? "Item" 
             : (
                   State().ShowManufacturer && Manufacturer != null 
                   ? Concat( Manufacturer, " ", Name ) 
                   : Name
               )
         }
         </label>
    </case>
</node-factory>
Tail

Returns a fragment of a string starting at the end and not exceeding the specified length.

  • A negative fragment length is normalized to zero.
  • A fragment length exceeding the length of the input is normalized to the length of the input.
${ Value.Tail( 3 ) }
${ Tail( "abcdef", 3 ) }
Text

Returns the text of a value, taking into account the default, if applicable.

${ PurchaseOrder.FulfillmentDate.Text }
This

In situations where EL context is established by a model element, it can be useful to directly reference that element in order to pass it to functions. Mirroring Java, the context now exposes "This" property.

In this example, the expression computes the index of the context model element within its parent list.

${ This.Index }
Validation

Returns the validation result of a property or a part.

${ PurchaseOrder.FulfillmentDate.Validation }
${ Part.Validation }

No comments: