Hi,
you have two options depending on the way you open a view:
- in case of navigation, you can open a view with wither route parameters or URL query parameters, e.g.:
viewNavigators.detailView(User.class)
.editEntity(entityToEdit) // .newEntity() in case of creation
.withQueryParameters(QueryParameters.of("someParam", "someValue"))
.navigate();
and handle these parameters:
@Subscribe
public void onQueryParametersChange(QueryParametersChangeEvent event) {
// handle params
}
- in case of opening a dialog window, you can create a setter method in your view and call this method before opening a dialog, e.g.:
DialogWindow<UserDetailView> dialogWindow = dialogWindows.detail(this, User.class)
.withViewClass(UserDetailView.class)
.editEntity(entityToEdit) // .newEntity() in case of creation
.build();
UserDetailView view = dialogWindow.getView();
view.setSomeParameter("someValue");
dialogWindow.open();
- since you want to handle
create
/edit
actions, you have the third option - InitEntityEvent
. This event is fired only if a view is opened for a new entity, so you can either do come logic in InitEntityEvent
handler or set a flag that a view is opened for creation rather that editing.
@Subscribe
public void onInitEntity(InitEntityEvent<User> event) {
// handle new entity creation
}
in addition, we provide the EntityStates
bean, which provides information about entity states: is it new, is it managed, ect. For example UserDetailView
uses it:
@Subscribe
public void onReady(ReadyEvent event) {
if (entityStates.isNew(getEditedEntity())) {
usernameField.focus();
}
}
Regards,
Gleb