如何在标准编辑界面中的onBeforeCommitChanges事件里判断实体当前是新增还是修改呢?
看 PersistenceHelper.isNew 可以用吗
可以的,感谢!
目前还有这个吗?
请问Jmix如何判断?
用 EntityStates
bean。Jmix项目自带了一个 UserEdit.java,里面有用法:
@Subscribe
protected void onBeforeCommit(BeforeCommitChangesEvent event) {
if (entityStates.isNew(getEditedEntity())) {
if (!Objects.equals(passwordField.getValue(), confirmPasswordField.getValue())) {
notifications.create(Notifications.NotificationType.WARNING)
.withCaption(messageBundle.getMessage("passwordsDoNotMatch"))
.show();
event.preventCommit();
}
getEditedEntity().setPassword(passwordEncoder.encode(passwordField.getValue()));
}
}