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:
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. 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...
The funny thing is that sometimes the entity is updated, and sometimes it is not... most of the time it works...