State Bean¶
State Beans are the mechanism for adding java based extensions to flows. They are the intended way to implement a custom Action Handler, Event Handler, or Screen Builder.
State Beans are any java class that is annotated with @State. When a class is annotated with @State it tells the
flow that this class can contain flow level logic that should be checked when specific functionality is invoked.
State Beans can be defined extremely specific where the action handler is targeting a specific state, within a specific flow, and for a specific app id. State Beans can also be defined as global State Beans that will be checked every time if that bean is qualified to be used.
Example¶
In some cases different Action Handlers might need to be used based on if the flow is being access from the POS or the Customer Display. To be able to handle this two different action handlers can be defined instead of making the action handler a more complicated function that has to know if it is in a given flow. This helps keep code separated and easier to test.
@State(name = "MyState", appId = "pos")
public class OnSomeActionPOS {
@ActionHandler
public void onSomeAction(Action action) {
...
}
}
@State(name = "MyState", appId = "customerdisplay")
public class OnSomeActionCustomerDisplay {
@ActionHandler
public void onSomeAction(Action action) {
...
}
}
Given the previous example, the OnSomeActionPOS would be used when SomeAction is fired while the device is a POS
and OnSomeActionCustomerDisplay when the device is a Customer Display.
Best Practices¶
- Group state beans in the same package as the State.
- If a State Bean is used by multiple states it can be moved into a package that makes it clear where it will be used.
- Make state beans single purpose.
Anti-patterns¶
- Do NOT combine unrelated Action Handlers, Event Handlers, or Screen Builders into a single State Bean.