CreateAction
– action with create identifier. It is intended to create new entity instance and open its edit screen. If the edit screen successfully commits
a new instance to the database, CreateAction
adds this new instance to the table data source and makes it selected.
The following specific methods are defined in the CreateAction
class:
-
setOpenType()
allows you to specify new entity edit screen open mode.THIS_TAB
by default.Since it is quite often required to open edit screens in another mode (typically,
DIALOG
), you can specify anopenType
attribute with desired value in theaction
element when using declarative creation of thecreate
action. This eliminates the need to obtain action reference in the controller and set this property programmatically. For example:<table id="usersTable"> <actions> <action id="create" openType="DIALOG"/>
-
setWindowId()
allows you to specify the identifier of the entity edit screen. By default,{entity_name}.edit
is used, for examplesales$Customer.edit
. -
setWindowParams()
allows you to set edit screen parameters passed into itsinit()
method. -
setInitialValues()
allows you to set initial values of attributes of the entity being created. It takes aMap
object, where keys are attribute names, and values are attribute values. For example:Map<String, Object> values = new HashMap<>(); values.put("type", CarType.PASSENGER); carCreateAction.setInitialValues(values);
An example of
setInitialValues()
usage is also provided in the section of development recipes. -
afterCommit()
is invoked by the action after the new entity has been successfully committed and the edit screen has been closed. This method does not have implementation and can be overridden in inheritors to handle this event. -
setAfterCommitHandler()
allows you to provide a handler which will be called after the new entity has been successfully committed and the edit screen has been closed. This handler can be used instead of overridingafterCommit()
to avoid creating the action subclass. For example:@Named("customersTable.create") private CreateAction customersTableCreate; @Override public void init(Map<String, Object> params) { customersTableCreate.setAfterCommitHandler(new CreateAction.AfterCommitHandler() { @Override public void handle(Entity entity) { showNotification("Committed", NotificationType.HUMANIZED); } }); }
-
afterWindowClosed()
is the last method invoked by the action after closing the edit screen regardless of whether the new entity has been committed or not. This method does not have implementation and can be overridden in inheritors to handle this event. -
setAfterWindowClosedHandler()
allows you to provide a handler which will be called after closing the edit screen regardless of whether the new entity has been committed or not. This handler can be used instead of overridingafterWindowClosed()
to avoid creating the action subclass.