Action: SET_CONTROL_ATTRIBUTES

This action is used to change the attributes of a control at run-time either before or after its placement on the screen. Initially the control and its attributes are defined in the XML file. For example, a text control could show the text in green if the value is positive or in red if the value is negative.

See a full list of Control Attributes that define location, size, appearance, data source and other properties. Controls may have extended properties as well and you can view details of a specific control to see the list. All extended properties can be set unless otherwise stated.

Attributes Value Mandatory
action_name SET_CONTROL_ATTRIBUTES Yes
event_list comma separated list of events, eg: TAP Yes
target comma separated list of control names Yes
input_parameter_list

comma separated list of values to be set. A value can be a

  • A constant value (CONSTANT:<value>) for ex. CONSTANT:3
  • A Global Property (GLOBAL:<property name> for ex. CONSTANT:home_url
  • Any field_name of the control present in the current screen.
  • A value from the database using SQL query.
  • Any parameter passed to the screen via action NEXT_SCREEN
  • Any parameter fetched from the remote_data_source (if one is present)
No
target_parameter_list See Control Attributes for full list of attributes that can be set to a control. See a specific control for extended_properties No

The attributes can be changed in two ways

  • Using the action “FUNCTION” - This is a most common way for changing the Control Attributes dynamically. Here the attributes are set by creating a new action and executing it. See the example below.
  • The XML definition file - The Control Attributes are changed by passing their attribute name in the target_parameter_list. See the example below.

Examples

Example 1 - Change the value of the control “mycontrol” to “you tapped!!!” when the user taps on the control

<control name="mycontrol" type="TEXT" x="20" y="8" width="35" height="7"
        appearance_name="black" data_type="STRING" default_value="not tapped"
        size="255">
    <action event_list="TAP" action_name="SET_CONTROL_ATTRIBUTES" target="mycontrol"
            input_parameter_list="CONSTANT:you tapped!!!" target_parameter_list="value"/>
</control>

Example 2 - Change the appearance of the control “mycontrol” by fetching the appearance name stored in column “color” in local database table called “mycolortable”.

<control name="mycontrol" type="TEXT" x="20" y="8" width="35"
        height="7"
        appearance_name="green" data_type="STRING"
        size="255">
    <action event_list="TAP" action_name="SET_CONTROL_ATTRIBUTES" target="mycontrol"
            input_parameter_list="&quot;select color from mycolortable&quot;" target_parameter_list="appearance_id"/>
</control>

Example 3 - Change the appearance of the control “mycontrol” to appearance “red” when the price is negative. In the example below, the action is defined for the element <screen> and is called on the event “ON_RESUME_SCREEN”. It looks for value of price and sets the appearance accordingly.

<screens>
    <screen name="remotelist" screen_type="SCREEN"
            initial_layout="PORTRAIT" allowed_layouts="BOTH"
            width="100" height="100">
    </screen>
    <actions>
        <action event_list="ON_RESUME_SCREEN" action_name="FUNCTION" target="myOnResumeFunction"/>
    </actions>
    <control name="mycontrol" type="TEXT" x="20" y="8" width="35"
            height="7"  default_value="$10.0"
            appearance_name="green" data_type="STRING"
            size="255">
    </control>
</screens>

Define a custom function called myOnResumeFunction

public class myOnResumeFunction implements CustomFunctionInterface {

    public myOnResumeFunction() {}

    @Override
    public Object execute(final Context ctx, final View v, final View pView, ActionModel a,
            Bundle targetParameterValueList) {

        float price = generateRandomNumber(1000, -1000); // Here it is randomly generated but generally fetched from a data source.

        // Create a new action to change the appearance
        ActionModel changeAppearance = new ActionModel(a.sSystemDbName, a.sContentDbName);
        // Set the action name
        changeAppearance.setActionName("SET_CONTROL_ATTRIBUTES");
        // Set the target
        changeAppearance.sTarget = "mycontrol";
        // Set the appearance_id = red. Appearance with name="red" or "green" are defined in the appearance.xml
        targetParameterValueList.putString("appearance_id", price > 0 ? "green" : "red");
        // Execute the action
        Action.callAction(ctx, v, pView, changeAppearance, targetParameterValueList);

        return Boolean.valueOf(true);
    }

    public static int generatRandomNumber(int max , int min) {
        Random rand = new Random();
        int ii = -min + (int) (Math.random() * ((max - (-min)) + 1));
        return ii;
    }
}