Custom State Variables

You can define input and output variables for custom states. Variables are used as both metadata in the state editor, and as runtime objects for storing session variables.

In the GetMyWeather sample custom state, one input variable (Zip or Postal Code) and one output variable (Your Weather Synopsis) are defined in the code, and appear in the state editor view.
// Define input variable
   
private static final TextBoxAttribute inPostCode = 
        new TextBoxAttribute("POSTCODE", "Zip or Postal Code", false);        
   
// Define output variable    
   
private static final OutputAttribute outWeather = 
        new OutputAttribute("WEATHER", "Your Weather Synopsis");        

private static Attribute[] stateAttr;        

static {       
   stateAttr = new Attribute[] {inPostCode, outWeather};    
}
        
@Override    
protected Attribute[] getStateAttributes() {       
   return stateAttr.clone();    
}


Custom Input and Output Variables

getStateAttributes is an abstract helper method that the SmappStatePlugin class implements. It aggregates both input and output variables. The base class derives the required getInputAttributes and getOutputAttributes methods from getStateAttributes, based on the attribute-type class. The state editor uses the attribute array that the getStateAttributes method returns to render input and output variables. The saveOutputAttributes method saves output attributes from the attribute array.

All variables (input and output) have input controls that appear on the state editor. The public String getText() method returns the text from input controls.

Related concepts
Input and Output Parameters
Defining Input Variables
Defining Output Variables
Accessing Input Variables
List Variables
Related reference
Sample GetMyWeather State