3.5.4.2.2. Picker Field Actions
The framework provides a set of standard actions for PickerField, LookupPickerField and SearchPickerField components.
An example of using standard actions in a picker component:
<pickerField id="userPickerField" dataContainer="employeeDc" property="user">
<actions>
<action id="lookup" type="picker_lookup"/>
<action id="open" type="picker_open"/>
<action id="clear" type="picker_clear"/>
</actions>
</pickerField>
The standard picker component actions include the following types:
-
picker_lookup
type is implemented by thecom.haulmont.cuba.gui.actions.picker.LookupAction
class. It is designed to select an entity instance from a lookup screen and set it to the picker field. -
picker_open
type is implemented by thecom.haulmont.cuba.gui.actions.picker.OpenAction
class. It is designed to open an editor screen for the entity currently selected in the picker field. -
picker_clear
type is implemented by thecom.haulmont.cuba.gui.actions.picker.ClearAction
class. It is designed to clear the picker field.
Standard actions provide default values for basic parameters: caption, icon and shortcut; and default behavior when executed. You can provide your own values to basic parameters in XML, just like for any other action. For example, you can specify a custom icon:
<action id="open" type="picker_open" icon="USER"/>
In order to customize the execution behavior, you should subscribe to the action’s ActionPerformedEvent
. All standard actions do not execute their code if an alternative action listener is provided. It means that your ActionPerformedEvent
handler effectively overrides the default action behavior.
For example, the following code overrides the default picker_lookup
action behavior to select User
entity using a specific screen opened as a modal dialog:
public class CustomerBrowse extends StandardLookup<Customer> {
@Inject
private ScreenBuilders screenBuilders;
@Inject
private PickerField<User> userPickerField;
@Subscribe("userPickerField.lookup")
protected void onUserPickerFieldLookupActionPerformed(Action.ActionPerformedEvent event) {
screenBuilders.lookup(User.class, this)
.withField(userPickerField)
.withScreenClass(UserBrowser.class) // specific lookup screen
.withLaunchMode(OpenMode.DIALOG) // open as modal dialog
.build()
.show();
}
See ScreenBuilders bean description for more details.