Function

From JRapid

Jump to: navigation, search

The "function" attribute specifies the name of the JavaScript function associated to this action.


Contents

Function prototype

The prototype of the javascript function to be invoked has to be of the following way:

Entity javascript actions

 function name(obj, ids, param1, param2, ... , paramN) {
    ...
 }
  • obj: object related to the action (eg. the input box).
  • ids: an array with the ids chosen from the list.
  • param_i: i extra param of the function.

Additionally the function can receive extra parameters if the purpose of the function requires them. For that you use the attribute functionparams and indicate the parameter list separating the parameters using a semi colon. Extra params can be only passed if the location of the action is "local".

Property javascript actions

 function name(obj) {
    ...
 }
  • obj: object related to the action (eg. the input box).

Next javascript function

 function name(key,obj) {
    ...
 }
  • key: the return value of the store() method in the Java services.
  • obj: object related to the action (eg. the input box).

To see how you can include a javascript file see usescript.

Example:

function showSelectedPersonInfo(obj, ids, firstName, lastName) {
    alert(firstName + " " + lastName + " id: " + ids);
}
<entity name="Person" label="Person">
     <property name="firstName" label="First name" display="secondary" />
     <property name="lastName" label="Last name" display="primary" />
     <action name="showSelected" location="local" type="javascript"
 function="showSelectedPersonInfo" functionparams="firstName;lastName"/>
</entity>

Usage:

 <action label=LABEL type="javascript" function=FUNCTION_NAME location=LOCATION/>

See also: