コード例 #1
0
ファイル: CustomerFormPanel.java プロジェクト: ralevuk/ehour
  public CustomerFormPanel(String id, CompoundPropertyModel<CustomerAdminBackingBean> model) {
    super(id, model);

    GreySquaredRoundedBorder greyBorder = new GreySquaredRoundedBorder("border");
    add(greyBorder);

    setOutputMarkupId(true);

    final Form<CustomerAdminBackingBean> form =
        new Form<CustomerAdminBackingBean>("customerForm", model);

    // name
    RequiredTextField<String> nameField = new RequiredTextField<String>("customer.name");
    form.add(nameField);

    nameField.add(StringValidator.lengthBetween(0, 64));
    nameField.setLabel(new ResourceModel("admin.customer.name"));
    nameField.add(new ValidatingFormComponentAjaxBehavior());
    form.add(new AjaxFormComponentFeedbackIndicator("nameValidationError", nameField));

    // code
    final RequiredTextField<String> codeField = new RequiredTextField<String>("customer.code");
    form.add(codeField);
    codeField.add(StringValidator.lengthBetween(0, 16));
    codeField.setLabel(new ResourceModel("admin.customer.code"));
    codeField.add(new ValidatingFormComponentAjaxBehavior());
    form.add(new UniqueCustomerValidator(nameField, codeField));
    form.add(new AjaxFormComponentFeedbackIndicator("codeValidationError", codeField));

    // description
    TextArea<String> textArea = new KeepAliveTextArea("customer.description");
    textArea.setLabel(new ResourceModel("admin.customer.description"));
    form.add(textArea);

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

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

    //

    boolean deletable = model.getObject().getCustomer().isDeletable();
    FormConfig formConfig =
        new FormConfig()
            .forForm(form)
            .withDelete(deletable)
            .withSubmitTarget(this)
            .withDeleteEventType(CustomerAjaxEventType.CUSTOMER_DELETED)
            .withSubmitEventType(CustomerAjaxEventType.CUSTOMER_UPDATED);

    FormUtil.setSubmitActions(formConfig);

    greyBorder.add(form);
  }
コード例 #2
0
ファイル: UserFormPanel.java プロジェクト: RobKuipers/ehour
  @Override
  protected void onInitialize() {
    super.onInitialize();

    IModel<T> userModel = getPanelModel();

    T manageUserBackingBean = getPanelModelObject();
    User user = manageUserBackingBean.getUser();

    boolean editMode = user.getPK() != null;

    GreySquaredRoundedBorder greyBorder = new GreySquaredRoundedBorder(BORDER, WebGeo.AUTO);
    add(greyBorder);

    setOutputMarkupId(true);

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

    createUsernameInput(form);
    createNameInput(form);
    createMailInput(form);
    createPasswordInput(userModel, manageUserBackingBean, form);
    createDepartmentInput(form);
    createRoleInput(form);
    createActiveInput(form);

    // show assignments
    CheckBox showAssignments = new CheckBox("showAssignments");
    showAssignments.setMarkupId("showAssignments");
    showAssignments.setVisible(!manageUserBackingBean.isEditMode());
    form.add(showAssignments);

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

    boolean deletable = user.isDeletable();

    FormConfig formConfig =
        FormConfig.forForm(form)
            .withDelete(deletable)
            .withDeleteEventType(USER_DELETED)
            .withSubmitTarget(this)
            .withSubmitEventType(editMode ? USER_UPDATED : USER_CREATED);

    FormUtil.setSubmitActions(formConfig);

    greyBorder.add(form);

    onFormCreated(form);
  }
コード例 #3
0
ファイル: UserAdminFormPanel.java プロジェクト: ralevuk/ehour
  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);
  }