Esempio n. 1
0
  private void createPasswordInput(IModel<T> userModel, T manageUserBackingBean, Form<T> form) {
    Label label = new Label("passwordEditLabel", new ResourceModel("admin.user.editPassword"));
    label.setVisible(manageUserBackingBean.isEditMode());
    form.add(label);

    PasswordFieldFactory.createOptionalPasswordFields(
        form, new PropertyModel<String>(userModel, "user.password"));
  }
Esempio n. 2
0
  public UserAdminFormPanel(
      String id,
      CompoundPropertyModel<UserBackingBean> userModel,
      List<UserRole> roles,
      List<UserDepartment> departments) {
    super(id, userModel);

    GreySquaredRoundedBorder greyBorder = new GreySquaredRoundedBorder(BORDER);
    add(greyBorder);

    setOutputMarkupId(true);

    final Form<UserBackingBean> form = new Form<UserBackingBean>(FORM, userModel);

    // username
    RequiredTextField<String> usernameField = new RequiredTextField<String>("user.username");
    form.add(usernameField);
    usernameField.add(new StringValidator(0, 32));
    usernameField.add(new DuplicateUsernameValidator());
    usernameField.setLabel(new ResourceModel("admin.user.username"));
    usernameField.add(new ValidatingFormComponentAjaxBehavior());
    form.add(new AjaxFormComponentFeedbackIndicator("userValidationError", usernameField));

    // user info
    TextField<String> firstNameField = new TextField<String>("user.firstName");
    form.add(firstNameField);

    TextField<String> lastNameField = new RequiredTextField<String>("user.lastName");
    form.add(lastNameField);
    lastNameField.setLabel(new ResourceModel("admin.user.lastName"));
    lastNameField.add(new ValidatingFormComponentAjaxBehavior());
    form.add(new AjaxFormComponentFeedbackIndicator("lastNameValidationError", lastNameField));

    form.add(new EmailInputSnippet("email"));

    // password
    Label label = new Label("passwordEditLabel", new ResourceModel("admin.user.editPassword"));
    label.setVisible(userModel.getObject().getAdminAction() == AdminAction.EDIT);
    form.add(label);

    PasswordFieldFactory.createOptionalPasswordFields(
        form, new PropertyModel<String>(userModel, "user.password"));

    // department
    DropDownChoice<UserDepartment> userDepartment =
        new DropDownChoice<UserDepartment>(
            "user.userDepartment", departments, new ChoiceRenderer<UserDepartment>("name"));
    userDepartment.setRequired(true);
    userDepartment.setLabel(new ResourceModel("admin.user.department"));
    userDepartment.add(new ValidatingFormComponentAjaxBehavior());
    form.add(userDepartment);
    form.add(new AjaxFormComponentFeedbackIndicator("departmentValidationError", userDepartment));

    // user roles
    ListMultipleChoice<UserRole> userRoles =
        new ListMultipleChoice<UserRole>("user.userRoles", roles, new UserRoleRenderer());
    userRoles.setMaxRows(4);
    userRoles.setLabel(new ResourceModel("admin.user.roles"));
    userRoles.setRequired(true);
    userRoles.add(new ValidatingFormComponentAjaxBehavior());
    form.add(userRoles);
    form.add(new AjaxFormComponentFeedbackIndicator("rolesValidationError", userRoles));

    // active
    form.add(new CheckBox("user.active"));

    // data save label
    form.add(new ServerMessageLabel("serverMessage", "formValidationError"));

    boolean deletable = userModel.getObject().getUser().isDeletable();

    FormConfig formConfig =
        new FormConfig()
            .forForm(form)
            .withDelete(deletable)
            .withSubmitTarget(this)
            .withDeleteEventType(UserEditAjaxEventType.USER_DELETED)
            .withSubmitEventType(UserEditAjaxEventType.USER_UPDATED);

    FormUtil.setSubmitActions(formConfig);

    greyBorder.add(form);
  }