IDEMPIERE-5888 Login Preferences are created on System tenant - fix NPE (#2229)

This commit is contained in:
Carlos Ruiz 2024-02-07 01:44:15 +01:00
parent 2727437688
commit 3ac70045f1
1 changed files with 29 additions and 21 deletions

View File

@ -91,9 +91,9 @@ import org.zkoss.zul.Image;
public class RolePanel extends Window implements EventListener<Event>, Deferrable public class RolePanel extends Window implements EventListener<Event>, Deferrable
{ {
/** /**
* generated serial id *
*/ */
private static final long serialVersionUID = -1159253307008488232L; private static final long serialVersionUID = -8077156023041816851L;
protected LoginWindow wndLogin; protected LoginWindow wndLogin;
protected Login login; protected Login login;
@ -554,6 +554,7 @@ public class RolePanel extends Window implements EventListener<Event>, Deferrabl
userPreference.setProperty(UserPreference.P_LANGUAGE, Env.getContext(m_ctx, UserPreference.LANGUAGE_NAME)); userPreference.setProperty(UserPreference.P_LANGUAGE, Env.getContext(m_ctx, UserPreference.LANGUAGE_NAME));
if (lstItemRole != null && lstItemRole.getValue() != null) if (lstItemRole != null && lstItemRole.getValue() != null)
userPreference.setProperty(UserPreference.P_ROLE, (String) lstItemRole.getValue()); userPreference.setProperty(UserPreference.P_ROLE, (String) lstItemRole.getValue());
if (lstItemClient != null && lstItemClient.getValue() != null)
userPreference.setProperty(UserPreference.P_CLIENT, (String) lstItemClient.getValue()); userPreference.setProperty(UserPreference.P_CLIENT, (String) lstItemClient.getValue());
if (lstItemOrg != null && lstItemOrg.getValue() != null) if (lstItemOrg != null && lstItemOrg.getValue() != null)
userPreference.setProperty(UserPreference.P_ORG, (String) lstItemOrg.getValue()); userPreference.setProperty(UserPreference.P_ORG, (String) lstItemOrg.getValue());
@ -729,14 +730,18 @@ public class RolePanel extends Window implements EventListener<Event>, Deferrabl
if(eventName.equals("onSelect")) if(eventName.equals("onSelect"))
{ {
if(eventCompId.equals(lstClient.getId())){ if(eventCompId.equals(lstClient.getId())){
checkMandatoryField(lstClient, lblClient);
updateRoleList(); updateRoleList();
} }
else if(eventCompId.equals(lstRole.getId())) { else if(eventCompId.equals(lstRole.getId())) {
checkMandatoryField(lstRole, lblRole);
setUserID(); setUserID();
updateOrganisationList(); updateOrganisationList();
} }
else if(eventCompId.equals(lstOrganisation.getId())) else if(eventCompId.equals(lstOrganisation.getId())) {
checkMandatoryField(lstOrganisation, lblOrganisation);
updateWarehouseList(); updateWarehouseList();
}
else if (eventCompId.equals(lstLanguage.getId())) else if (eventCompId.equals(lstLanguage.getId()))
{ {
if (lstLanguage.getSelectedItem() == null) if (lstLanguage.getSelectedItem() == null)
@ -847,18 +852,9 @@ public class RolePanel extends Window implements EventListener<Event>, Deferrabl
Comboitem lstItemWarehouse = lstWarehouse.getSelectedItem(); Comboitem lstItemWarehouse = lstWarehouse.getSelectedItem();
Comboitem lstItemLanguage = lstLanguage.getSelectedItem(); Comboitem lstItemLanguage = lstLanguage.getSelectedItem();
if(lstItemRole == null || lstItemRole.getValue() == null) checkMandatoryField(lstClient, lblClient);
{ checkMandatoryField(lstRole, lblRole);
throw new WrongValueException(lstRole, Msg.getMsg(m_ctx, "FillMandatory") + lblRole.getValue()); checkMandatoryField(lstOrganisation, lblOrganisation);
}
else if(lstItemClient == null || lstItemClient.getValue() == null)
{
throw new WrongValueException(lstClient, Msg.getMsg(m_ctx, "FillMandatory") + lblClient.getValue());
}
else if(lstItemOrg == null || lstItemOrg.getValue() == null)
{
throw new WrongValueException(lstOrganisation, Msg.getMsg(m_ctx, "FillMandatory") + lblOrganisation.getValue());
}
int orgId = 0, warehouseId = 0; int orgId = 0, warehouseId = 0;
orgId = Integer.parseInt((String)lstItemOrg.getValue()); orgId = Integer.parseInt((String)lstItemOrg.getValue());
KeyNamePair orgKNPair = new KeyNamePair(orgId, lstItemOrg.getLabel()); KeyNamePair orgKNPair = new KeyNamePair(orgId, lstItemOrg.getLabel());
@ -929,6 +925,18 @@ public class RolePanel extends Window implements EventListener<Event>, Deferrabl
desktop.getSession().setAttribute(SSOUtils.ISCHANGEROLE_REQUEST, false); desktop.getSession().setAttribute(SSOUtils.ISCHANGEROLE_REQUEST, false);
} }
/**
* Check if the field is filled, throws WrongValueException if not
* @param lst
* @param lbl
*/
private void checkMandatoryField(Combobox lst, Label lbl) {
Comboitem item = lst.getSelectedItem();
if (item == null || item.getValue() == null) {
throw new WrongValueException(lst, Msg.getMsg(m_ctx, "FillMandatory") + lbl.getValue());
}
}
@Override @Override
public boolean isDeferrable() { public boolean isDeferrable() {
return false; return false;