/** * Create toolbar for editing an existing object * * @param aWPEC The web page execution context. Never <code>null</code>. * @param aForm The handled form. Never <code>null</code>. * @param aSelectedObject The selected object. Never <code>null</code>. * @return Never <code>null</code>. */ @Nonnull @OverrideOnDemand protected IButtonToolbar<?> createEditToolbar( @Nonnull final WPECTYPE aWPEC, @Nonnull final HCForm aForm, @Nonnull final DATATYPE aSelectedObject) { final IButtonToolbar<?> aToolbar = createNewEditToolbar(aWPEC); aToolbar.addHiddenField(CHCParam.PARAM_ACTION, ACTION_EDIT); aToolbar.addHiddenField(CHCParam.PARAM_OBJECT, aSelectedObject.getID()); aToolbar.addHiddenField(CHCParam.PARAM_SUBACTION, ACTION_SAVE); // Save button aToolbar.addSubmitButtonSave(aWPEC.getDisplayLocale()); // Cancel button aToolbar.addButtonCancel(aWPEC.getDisplayLocale()); modifyEditToolbar(aWPEC, aSelectedObject, aToolbar); return aToolbar; }
@Override protected boolean handleCustomActions( @Nonnull final WebPageExecutionContext aWPEC, @Nullable final IUser aSelectedObject) { if (aWPEC.hasAction(ACTION_RESET_PASSWORD) && aSelectedObject != null) { if (!canResetPassword(aSelectedObject)) throw new IllegalStateException("Won't work!"); final Locale aDisplayLocale = aWPEC.getDisplayLocale(); final boolean bShowForm = true; final FormErrors aFormErrors = new FormErrors(); if (aWPEC.hasSubAction(ACTION_PERFORM)) { final String sPlainTextPassword = aWPEC.getAttr(FIELD_PASSWORD); final String sPlainTextPasswordConfirm = aWPEC.getAttr(FIELD_PASSWORD_CONFIRM); final List<String> aPasswordErrors = GlobalPasswordSettings.getPasswordConstraintList() .getInvalidPasswordDescriptions(sPlainTextPassword, aDisplayLocale); for (final String sPasswordError : aPasswordErrors) aFormErrors.addFieldError(FIELD_PASSWORD, sPasswordError); if (!EqualsUtils.equals(sPlainTextPassword, sPlainTextPasswordConfirm)) aFormErrors.addFieldError( FIELD_PASSWORD_CONFIRM, EText.ERROR_PASSWORDS_DONT_MATCH.getDisplayText(aDisplayLocale)); if (aFormErrors.isEmpty()) { AccessManager.getInstance().setUserPassword(aSelectedObject.getID(), sPlainTextPassword); aWPEC .getNodeList() .addChild( getStyler() .createSuccessBox( EText.SUCCESS_RESET_PASSWORD.getDisplayTextWithArgs( aDisplayLocale, SecurityUI.getUserDisplayName(aSelectedObject, aDisplayLocale)))); return true; } } if (bShowForm) { // Show input form final boolean bHasAnyPasswordConstraint = GlobalPasswordSettings.getPasswordConstraintList().hasConstraints(); final HCForm aForm = aWPEC.getNodeList().addAndReturnChild(createFormSelf()); final IHCTableForm<?> aTable = aForm.addAndReturnChild( getStyler().createTableForm(new HCCol(200), HCCol.star(), new HCCol(20))); aTable.setSpanningHeaderContent( EText.TITLE_RESET_PASSWORD.getDisplayTextWithArgs( aDisplayLocale, SecurityUI.getUserDisplayName(aSelectedObject, aDisplayLocale))); final String sPassword = EText.LABEL_PASSWORD.getDisplayText(aDisplayLocale); aTable .createItemRow() .setLabel( sPassword, bHasAnyPasswordConstraint ? ELabelType.MANDATORY : ELabelType.OPTIONAL) .setCtrl(new HCEditPassword(FIELD_PASSWORD).setPlaceholder(sPassword)) .setNote(SecurityUI.createPasswordConstraintTip(aDisplayLocale)) .setErrorList(aFormErrors.getListOfField(FIELD_PASSWORD)); final String sPasswordConfirm = EText.LABEL_PASSWORD_CONFIRM.getDisplayText(aDisplayLocale); aTable .createItemRow() .setLabel( sPasswordConfirm, bHasAnyPasswordConstraint ? ELabelType.MANDATORY : ELabelType.OPTIONAL) .setCtrl(new HCEditPassword(FIELD_PASSWORD_CONFIRM).setPlaceholder(sPasswordConfirm)) .setNote(SecurityUI.createPasswordConstraintTip(aDisplayLocale)) .setErrorList(aFormErrors.getListOfField(FIELD_PASSWORD_CONFIRM)); final IButtonToolbar<?> aToolbar = aForm.addAndReturnChild(getStyler().createToolbar()); aToolbar.addHiddenField(CHCParam.PARAM_ACTION, ACTION_RESET_PASSWORD); aToolbar.addHiddenField(CHCParam.PARAM_OBJECT, aSelectedObject.getID()); aToolbar.addHiddenField(CHCParam.PARAM_SUBACTION, ACTION_PERFORM); aToolbar.addSubmitButtonSave(aDisplayLocale); aToolbar.addButtonCancel(aDisplayLocale); } return false; } return true; }