简体   繁体   English

小门形式变化随机被忽略

[英]Wicket Form changes randomly being ignored

I had a problem with a Form Field ( Transient wicket form field ignored ) and I had no much luck with the answers, so I made some changes and now the field is sometimes updated, and sometimes not... here's the current code: 我遇到了一个Form Field( 暂态wicket form字段被忽略 )的问题,我对答案没有太多的运气,所以我做了一些更改,现在该字段有时被更新了,有时却没有更新……这是当前代码:

The User entity: 用户实体:

@Entity(name = "user")
@Audited
public class User extends DataObjectAudit {

    private static final long serialVersionUID = 1L;

    private RoleTypeEnum role = null;

    public RoleTypeEnum getRole() {
        return role;
    }

    public void setRole(RoleTypeEnum role) {
        this.role = role;
    }
}

And in the panel, there is a drop down panel (extends GenericPanel) and the options possible are the current active role of the user is loaded among with the "lower" possible roles. 在该面板中,有一个下拉面板(扩展了GenericPanel),可能的选项是在加载用户的当前活动角色以及其中的“较低”角色中。 The chosen option should be loaded into the "role" property. 所选选项应加载到“角色”属性中。

User sessionUser = StudySession.getSessionUser();
List<RoleTypeEnum> roles = new ArrayList<RoleTypeEnum>();
roles.addAll(sessionUser.getRole().getLowerAndEqualsThanSelf());

WefDropDownPanel<RoleTypeEnum> role = new WefDropDownPanel<RoleTypeEnum>(helper.of(RoleTypeEnum.class, "role").errorRequired(), roles).setSizes(Size.S0, Size.S1, Size.S4);
add(role);

There is no validation for that field, others have though. 尽管没有其他人对此字段进行验证。

The only thing that is made before saving the form is: 保存表单之前唯一要做的是:

@Override
    protected void onBeforeSave(AjaxRequestTarget target, WefForm<User> form) {
        User user = getModelObject();
        DataService dataService = ServiceFactory.getBean(DataService.class);
        ProjectCenter projectCenter = dataService.findUniqueByParameters(ProjectCenter.class, new Parameter<Object>("center", user.getCenter()));
        if (projectCenter != null) {
            user.setProject(projectCenter.getProject());
        }
    }

So the result is that sometimes "role" is updated, and sometimes it is not... Also, all the other fields (that I have erased to simplify) are also being ignored... 因此,结果是有时“角色”被更新,有时未更新...。此外,所有其他字段(为简化起见,我已将其删除)也被忽略了...

If I erase the onBeforeSubmit method, the result is the same... sometimes the entity is updated with the values the user entered, sometimes not... 如果我删除onBeforeSubmit方法,则结果是相同的...有时该实体使用用户输入的值进行更新,有时不是...

The funny thing is that sometimes the entity is updated, and sometimes it is not... most of the time it works... 有趣的是,有时实体会被更新,有时却不会。

创建一个快速入门并在用户列表上进行报告-我将很乐意调试该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM