private void setFormFieldsFromQuestion(Question question) {
    Answer.AnswerType aType = question.getAnswerType();

    questionTitleField.setModelObject(question.getTitle());
    questionPromptField.setModelObject(question.getPrompt());
    questionPrefaceField.setModelObject(question.getPreface());
    questionCitationField.setModelObject(question.getCitation());
    questionResponseTypeModel.setObject(question.getAnswerType());
    Long answerReasonId = question.getAnswerReasonExpressionId();
    questionAnswerReasonModel.setObject(
        answerReasonId == null ? answerAlways : Expressions.get(answerReasonId));
    String msg = "Asking style in setFormFields: " + askingStyleModel.getObject();
    askingStyleModel.setObject(question.getAskingStyleList());
    msg +=
        " -> "
            + askingStyleModel.getObject()
            + " (question had "
            + question.getAskingStyleList()
            + ")";
    // throw new RuntimeException(msg);
    // questionUseIfField.setModelObject(question.getUseIfExpression());
    otherSpecifyCheckBox.setModelObject(question.getOtherSpecify());
    noneButtonCheckBox.setModelObject(question.getNoneButton());
    if (aType == Answer.AnswerType.NUMERICAL) {
      numericLimitsPanel.setVisible(true);
    } else if (aType == Answer.AnswerType.MULTIPLE_SELECTION) {
      multipleSelectionLimitsPanel.setVisible(true);
      noneButtonLabel.setVisible(true);
      noneButtonCheckBox.setVisible(true);
    }
    if (aType == Answer.AnswerType.SELECTION || aType == Answer.AnswerType.MULTIPLE_SELECTION) {
      otherSpecifyLabel.setVisible(true);
      otherSpecifyCheckBox.setVisible(true);
    } else {
      otherSpecifyLabel.setVisible(false);
      otherSpecifyCheckBox.setVisible(false);
    }
    if (aType == Answer.AnswerType.DATE || aType == Answer.AnswerType.TIME_SPAN) {
      timeUnitsPanel.setVisible(true);
    } else {
      timeUnitsPanel.setVisible(false);
    }
    numericLimitsPanel.setMinLimitType(question.getMinLimitType());
    numericLimitsPanel.setMinLiteral(question.getMinLiteral());
    numericLimitsPanel.setMinPrevQues(question.getMinPrevQues());
    numericLimitsPanel.setMaxLimitType(question.getMaxLimitType());
    numericLimitsPanel.setMaxLiteral(question.getMaxLiteral());
    numericLimitsPanel.setMaxPrevQues(question.getMaxPrevQues());

    multipleSelectionLimitsPanel.setMinCheckableBoxes(question.getMinCheckableBoxes());
    multipleSelectionLimitsPanel.setMaxCheckableBoxes(question.getMaxCheckableBoxes());

    listLimitsPanel.setQuestion(question);
  }
Beispiel #2
0
 public LinkPanel(
     String wicketId,
     String bootstrapIcon,
     String linkCssClass,
     IModel<String> model,
     Class<? extends WebPage> clazz,
     PageParameters parameters,
     boolean newWindow) {
   super(wicketId);
   this.labelModel = model;
   Link<Void> link = null;
   if (parameters == null) {
     link = new BookmarkablePageLink<Void>("link", clazz);
   } else {
     link = new BookmarkablePageLink<Void>("link", clazz, parameters);
   }
   if (newWindow) {
     link.add(new SimpleAttributeModifier("target", "_blank"));
   }
   if (linkCssClass != null) {
     link.add(new SimpleAttributeModifier("class", linkCssClass));
   }
   Label icon = new Label("icon");
   if (StringUtils.isEmpty(bootstrapIcon)) {
     link.add(icon.setVisible(false));
   } else {
     WicketUtils.setCssClass(icon, bootstrapIcon);
     link.add(icon);
   }
   link.add(new Label("label", labelModel).setRenderBodyOnly(true));
   add(link);
 }
  private void checkResponse(AjaxRequestTarget target) {
    // Show cancel
    if (response.isCancelVisible()) {
      cancelDiv.setVisible(true);
      target.addComponent(cancelDiv);
    }
    // Show retry
    if (response.isRetryVisible()) {
      retryDiv.setVisible(true);
      target.addComponent(retryDiv);
    }

    // Show error Text
    if (PortalUtils.exists(response.getErrorMessage())) {
      errorMsg.setVisible(true);
      target.addComponent(errorMsg);
    }

    // Return to URL
    if (PortalUtils.exists(response.getReturnUrl()) && response.isRedirect())
      try {
        getWebRequestCycle()
            .getWebResponse()
            .getHttpServletResponse()
            .sendRedirect(response.getReturnUrl());
        isRedirected = true;
      } catch (IOException e) {
        LOG.error(
            "#An error occurred while redirecting to the return url["
                + response.getReturnUrl()
                + "]",
            e);
        return;
      }
  }
Beispiel #4
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"));
  }
Beispiel #5
0
  @SuppressWarnings("rawtypes")
  public RestaurantPage(Restaurant r) {
    add(new Label("nameText", r.getName()));
    User user = BaseSession.get().getUser();
    List<Order> order_list = new ArrayList<Order>();
    try {
      order_list = orders.getHistory(r);
    } catch (LoadOrderException e) {
      // TODO Auto-generated catch block
      // e.printStackTrace();
    }
    int orderId = -1;
    for (Order order : order_list) {
      if (order.getUser().equals(user) && order.getStatus() == 0) {
        orderId = order.getId();
      }
    }
    Label lbl_order = new Label("orderText", "Su numero de pedido es: " + orderId);
    add(lbl_order.setVisible(orderId != -1));

    add(new Label("score", String.valueOf(r.getScore())));
    add(new Label("count", String.valueOf(r.getCountComments())));

    Link menuLink =
        new Link("menuLink") {

          @Override
          public void onClick() {
            setResponsePage(new RestaurantMenuPage(r.getId()));
          }
        };
    add(menuLink.setVisible(true));

    Link infoLink =
        new Link("infoLink") {

          @Override
          public void onClick() {}
        };
    add(infoLink.setVisible(true));

    add(new Label("descriptionText", r.getDescription()));
    boolean isClosed = false;
    ClosingPeriod cp = closingPeriods.getLastClosingPeriod(r);
    if (cp != null) {
      isClosed = !(new LocalDate()).isAfter(new LocalDate(cp.getFrom()));
    }
    add(
        new Label("restClose", new StringResourceModel("close", this, new Model<ClosingPeriod>(cp)))
            .setEscapeModelStrings(false)
            .setVisible(isClosed));
  }
  /**
   * called by the dropdownchoice when its selection changes to hide/make visible panels that deal
   * with range limits and the 'Other/Specify' check box the value we get from the ajax onUpdate
   * getModelValue() is a string indicating the position of the selected choice in the drop down
   *
   * @param iValue
   */
  protected void onSelectionChanged(int iValue) {
    boolean numericLimitsVisible = false;
    boolean multipleSelectionLimitsVisible = false;
    boolean timeSpanUnitsVisible = false;
    boolean otherSpecifyVisible = false;
    boolean listLimitsVisible = false;
    boolean isListStyle = (Boolean) askingStyleModel.getObject();

    switch (iValue) {
      case 0: // TEXT
        break;
      case 1: // NUMERIC
        numericLimitsVisible = true;
        break;
      case 2: // DROP_DOWN - single SELECTION
        otherSpecifyVisible = true;
        listLimitsVisible = isListStyle;
        break;
      case 3: // MULTIPLE_SELECTION
        multipleSelectionLimitsVisible = true;
        otherSpecifyVisible = true;
        listLimitsVisible = isListStyle;
        break;
      case 4: // DATE
      case 5: // TIME_SPAN
        timeSpanUnitsVisible = true;
        break;
    }

    numericLimitsPanel.setVisible(numericLimitsVisible);
    multipleSelectionLimitsPanel.setVisible(multipleSelectionLimitsVisible);
    noneButtonLabel.setVisible(multipleSelectionLimitsVisible);
    noneButtonCheckBox.setVisible(multipleSelectionLimitsVisible);
    otherSpecifyLabel.setVisible(otherSpecifyVisible);
    otherSpecifyCheckBox.setVisible(otherSpecifyVisible);
    timeUnitsPanel.setVisible(timeSpanUnitsVisible);
    timeUnitsPanel.setWeeksVisible((iValue == 5) ? true : false);
    listLimitsPanel.setVisible(listLimitsVisible);
  }
  /** {@inheritDoc} */
  @Override
  protected List<Component> createFormComponents() {
    List<Component> components = new ArrayList<Component>();

    components.add(this.createTextField("username"));

    Label label = new Label("passwordLabel", "Password:"******"password");
    passwordField.setVisible(this.getFormType().isNew());
    components.add(passwordField);

    return components;
  }
Beispiel #8
0
  @Override
  protected void onBeforeRender() {

    boolean showSave = false;
    String savePercent = "";
    final String lang = getLocale().getLanguage();

    BigDecimal priceToFormat = productPriceModel.getRegularPrice();
    String cssModificator = "regular";
    if (productPriceModel.getSalePrice() != null
        && MoneyUtils.isFirstBiggerThanSecond(
            productPriceModel.getRegularPrice(), productPriceModel.getSalePrice())) {
      priceToFormat = productPriceModel.getSalePrice();
      cssModificator = "sale";
      showSave = this.showSavings;
      if (showSave) {
        final BigDecimal save =
            MoneyUtils.getDiscountDisplayValue(
                productPriceModel.getRegularPrice(), productPriceModel.getSalePrice());
        savePercent = save.toString();
      }
    }
    final String[] formatted = getFormattedPrice(priceToFormat);

    addOrReplace(
        new Label(WHOLE_LABEL, formatted[0])
            .add(new AttributeModifier(HTML_CLASS, cssModificator + CSS_SUFFIX_WHOLE)));
    addOrReplace(
        new Label(DOT_LABEL, ".")
            .setVisible(
                StringUtils.isNotBlank(formatted[0]) || StringUtils.isNotBlank(formatted[1]))
            .add(new AttributeModifier(HTML_CLASS, cssModificator + CSS_SUFFIX_DOT)));
    addOrReplace(
        new Label(DECIMAL_LABEL, formatted[1])
            .setVisible(
                StringUtils.isNotBlank(formatted[0]) || StringUtils.isNotBlank(formatted[1]))
            .add(new AttributeModifier(HTML_CLASS, cssModificator + CSS_SUFFIX_DECIMAL)));

    final Pair<String, Boolean> symbol =
        currencySymbolService.getCurrencySymbol(productPriceModel.getCurrency());

    addOrReplace(
        new Label(CURRENCY_LABEL, symbol.getFirst())
            .setVisible(showCurrencySymbol && !symbol.getSecond())
            .setEscapeModelStrings(false)
            .add(new AttributeModifier(HTML_CLASS, cssModificator + CSS_SUFFIX_CURRENCY)));

    addOrReplace(
        new Label(CURRENCY2_LABEL, symbol.getFirst())
            .setVisible(showCurrencySymbol && symbol.getSecond())
            .setEscapeModelStrings(false)
            .add(new AttributeModifier(HTML_CLASS, cssModificator + CSS_SUFFIX_CURRENCY)));

    final Map<String, Object> tax = new HashMap<String, Object>();
    if (this.showTaxAmount) {
      tax.put(
          "tax",
          this.productPriceModel.getPriceTax() != null
              ? this.productPriceModel.getPriceTax().toPlainString()
              : Total.ZERO.toPlainString());
    } else {
      tax.put(
          "tax",
          this.productPriceModel.getPriceTaxRate() != null
              ? this.productPriceModel.getPriceTaxRate().stripTrailingZeros().toPlainString() + "%"
              : "0%");
    }
    tax.put("code", this.productPriceModel.getPriceTaxCode());

    final String taxNote = this.showTaxNet ? "taxNoteNet" : "taxNoteGross";

    addOrReplace(
        new Label(TAX_LABEL, WicketUtil.createStringResourceModel(this, taxNote, tax))
            .setVisible(this.showTax)
            .add(new AttributeModifier(HTML_CLASS, cssModificator + CSS_SUFFIX_TAX)));

    final Label discount =
        new Label(
            SAVE_LABEL,
            WicketUtil.createStringResourceModel(
                this,
                "savePercent",
                Collections.<String, Object>singletonMap("discount", savePercent)));

    discount.setVisible(showSave);
    discount.add(new AttributeModifier(HTML_CLASS, "sale-price-save"));

    if (showSave && StringUtils.isNotBlank(promos)) {

      final Map<String, ProductPromotionModel> promoModels =
          productServiceFacade.getPromotionModel(promos);

      final StringBuilder details = new StringBuilder();
      for (final ProductPromotionModel model : promoModels.values()) {

        final String name = model.getName().getValue(lang);
        final String desc = model.getDescription().getValue(lang);

        details.append(name);
        if (model.getCouponCode() != null) {
          details.append(" (").append(model.getCouponCode()).append(")");
        }

        if (StringUtils.isNotBlank(desc)) {
          details.append(": ").append(desc);
        }
        details.append("\n");
      }

      discount.add(new AttributeModifier("title", details.toString()));
    } else {
      discount.add(
          new AttributeModifier(
              "title", WicketUtil.createStringResourceModel(this, "savePercentTitle")));
    }

    addOrReplace(discount);

    addOrReplace(
        new Label(PROMO_LABEL, promos)
            .setVisible(StringUtils.isNotBlank(promos))
            .add(new AttributeModifier(HTML_CLASS, "sale-price-save sale-price-save-details")));

    super.onBeforeRender();
  }
  @SuppressWarnings({"rawtypes", "unchecked"})
  public GeoServerHomePage() {
    GeoServer gs = getGeoServer();
    ContactInfo contact = gs.getGlobal().getSettings().getContact();

    // add some contact info
    add(
        new ExternalLink("contactURL", contact.getOnlineResource())
            .add(new Label("contactName", contact.getContactOrganization())));
    {
      String version = String.valueOf(new ResourceModel("version").getObject());
      String contactEmail = contact.getContactEmail();
      HashMap<String, String> params = new HashMap<String, String>();
      params.put("version", version);
      params.put("contactEmail", (contactEmail == null ? "*****@*****.**" : contactEmail));
      Label label =
          new Label(
              "footerMessage",
              new StringResourceModel("GeoServerHomePage.footer", this, new Model(params)));
      label.setEscapeModelStrings(false);
      add(label);
    }

    Authentication auth = getSession().getAuthentication();
    if (isAdmin(auth)) {
      Stopwatch sw = Stopwatch.createStarted();
      Fragment f = new Fragment("catalogLinks", "catalogLinksFragment", this);
      Catalog catalog = getCatalog();

      NumberFormat numberFormat = NumberFormat.getIntegerInstance(getLocale());
      numberFormat.setGroupingUsed(true);

      final Filter allLayers = acceptAll();
      final Filter allStores = acceptAll();
      final Filter allWorkspaces = acceptAll();

      final int layerCount = catalog.count(LayerInfo.class, allLayers);
      final int storesCount = catalog.count(StoreInfo.class, allStores);
      final int wsCount = catalog.count(WorkspaceInfo.class, allWorkspaces);

      f.add(
          new BookmarkablePageLink("layersLink", LayerPage.class)
              .add(new Label("nlayers", numberFormat.format(layerCount))));
      f.add(new BookmarkablePageLink("addLayerLink", NewLayerPage.class));

      f.add(
          new BookmarkablePageLink("storesLink", StorePage.class)
              .add(new Label("nstores", numberFormat.format(storesCount))));
      f.add(new BookmarkablePageLink("addStoreLink", NewDataPage.class));

      f.add(
          new BookmarkablePageLink("workspacesLink", WorkspacePage.class)
              .add(new Label("nworkspaces", numberFormat.format(wsCount))));
      f.add(new BookmarkablePageLink("addWorkspaceLink", WorkspaceNewPage.class));
      add(f);

      sw.stop();
    } else {
      Label placeHolder = new Label("catalogLinks");
      placeHolder.setVisible(false);
      add(placeHolder);
    }

    final IModel<List<GeoServerHomePageContentProvider>> contentProviders;
    contentProviders = getContentProviders(GeoServerHomePageContentProvider.class);
    ListView<GeoServerHomePageContentProvider> contentView =
        new ListView<GeoServerHomePageContentProvider>("contributedContent", contentProviders) {
          private static final long serialVersionUID = 1L;

          @Override
          protected void populateItem(ListItem<GeoServerHomePageContentProvider> item) {
            GeoServerHomePageContentProvider provider = item.getModelObject();
            Component extraContent = provider.getPageBodyComponent("contentList");
            if (null == extraContent) {
              Label placeHolder = new Label("contentList");
              placeHolder.setVisible(false);
              extraContent = placeHolder;
            }
            item.add(extraContent);
          }
        };
    add(contentView);

    final IModel<List<CapabilitiesHomePageLinkProvider>> capsProviders;
    capsProviders = getContentProviders(CapabilitiesHomePageLinkProvider.class);

    ListView<CapabilitiesHomePageLinkProvider> capsView =
        new ListView<CapabilitiesHomePageLinkProvider>("providedCaps", capsProviders) {
          private static final long serialVersionUID = 1L;

          @Override
          protected void populateItem(ListItem<CapabilitiesHomePageLinkProvider> item) {
            CapabilitiesHomePageLinkProvider provider = item.getModelObject();
            Component capsList = provider.getCapabilitiesComponent("capsList");
            item.add(capsList);
          }
        };
    add(capsView);
  }
  private void build() {

    feedbackPanel = new FeedbackPanel("feedback");
    add(feedbackPanel);

    form = new Form("questionForm");
    form.setOutputMarkupId(true);

    questionTitleField = new TextField("questionTitleField", new Model(""));
    questionTitleField.setRequired(true);
    questionTitleField.add(new FocusOnLoadBehavior());
    form.add(questionTitleField);

    if (question.getType().equals(Question.QuestionType.ALTER)) {
      form.add(new Label("promptHelpText", "(Refer to the alter as $$)"));
    } else if (question.getType().equals(Question.QuestionType.ALTER_PAIR)) {
      form.add(new Label("promptHelpText", "(Refer to the alters as $$1 and $$2)"));
    } else {
      form.add(new Label("promptHelpText", ""));
    }

    numericLimitsPanel = new NumericLimitsPanel("numericLimitsPanel", question);
    form.add(numericLimitsPanel);
    numericLimitsPanel.setVisible(false);

    multipleSelectionLimitsPanel = new MultipleSelectionLimitsPanel("multipleSelectionLimitsPanel");
    form.add(multipleSelectionLimitsPanel);
    multipleSelectionLimitsPanel.setVisible(false);

    timeUnitsPanel = new TimeUnitsPanel("timeUnitsPanel", question);
    form.add(timeUnitsPanel);
    timeUnitsPanel.setVisible(false);

    listLimitsPanel = new ListLimitsPanel("listLimitsPanel", question);
    form.add(listLimitsPanel);
    listLimitsPanel.setVisible(question.getAskingStyleList());

    questionPromptField = new TextArea("questionPromptField", new Model(""));
    questionPromptField.setRequired(true);
    form.add(questionPromptField);

    questionPrefaceField = new TextArea("questionPrefaceField", new Model(""));
    form.add(questionPrefaceField);

    questionCitationField = new TextArea("questionCitationField", new Model(""));
    form.add(questionCitationField);

    questionResponseTypeModel = new Model(Answer.AnswerType.TEXTUAL); // Could also leave this null.
    dropDownQuestionTypes =
        new DropDownChoice(
            "questionResponseTypeField",
            questionResponseTypeModel,
            Arrays.asList(Answer.AnswerType.values()));

    dropDownQuestionTypes.add(
        new AjaxFormComponentUpdatingBehavior("onchange") {
          protected void onUpdate(AjaxRequestTarget target) {
            onSelectionChanged(Integer.parseInt(dropDownQuestionTypes.getModelValue()));
            // target.addComponent(form);
            target.addComponent(numericLimitsPanel);
            target.addComponent(multipleSelectionLimitsPanel);
            target.addComponent(noneButtonLabel);
            target.addComponent(noneButtonCheckBox);
            target.addComponent(otherSpecifyLabel);
            target.addComponent(otherSpecifyCheckBox);
            target.addComponent(timeUnitsPanel);
            target.addComponent(listLimitsPanel);
          }
        });

    form.add(dropDownQuestionTypes);

    questionAnswerReasonModel = new Model(answerAlways);
    List<Object> answerChoices = new ArrayList<Object>();
    answerChoices.add(answerAlways);
    for (Expression expression : Expressions.forStudy(question.getStudyId())) {
      answerChoices.add(expression);
    }
    form.add(
        new DropDownChoice("questionAnswerReasonField", questionAnswerReasonModel, answerChoices));

    Label askingStyleListLabel = new Label("askingStyleListLabel", "Ask with list of alters:");
    askingStyleModel = new Model();
    askingStyleModel.setObject(Boolean.FALSE);
    AjaxCheckBox askingStyleListField =
        new AjaxCheckBox("askingStyleListField", askingStyleModel) {
          protected void onUpdate(AjaxRequestTarget target) {
            Boolean listLimitsVisible = false;

            if (questionResponseTypeModel.getObject().equals(Answer.AnswerType.MULTIPLE_SELECTION)
                || questionResponseTypeModel.getObject().equals(Answer.AnswerType.SELECTION))
              listLimitsVisible = (Boolean) askingStyleModel.getObject();

            listLimitsPanel.setVisible(listLimitsVisible);
            target.addComponent(form);
          }
        };
    askingStyleListLabel.setOutputMarkupId(true);
    askingStyleListLabel.setOutputMarkupPlaceholderTag(true);
    askingStyleListField.setOutputMarkupId(true);
    askingStyleListField.setOutputMarkupPlaceholderTag(true);
    form.add(askingStyleListLabel);
    form.add(askingStyleListField);
    if (question.getType().equals(Question.QuestionType.EGO)
        || question.getType().equals(Question.QuestionType.EGO_ID)) {
      askingStyleListLabel.setVisible(false);
      askingStyleListField.setVisible(false);
    }

    otherSpecifyLabel = new Label("otherSpecifyLabel", "Other/Specify Type Question?: ");
    otherSpecifyModel = new Model();
    otherSpecifyModel.setObject(Boolean.FALSE);
    otherSpecifyCheckBox = new CheckBox("otherSpecifyField", otherSpecifyModel);
    form.add(otherSpecifyLabel);
    form.add(otherSpecifyCheckBox);
    otherSpecifyLabel.setOutputMarkupId(true);
    otherSpecifyCheckBox.setOutputMarkupId(true);
    otherSpecifyLabel.setOutputMarkupPlaceholderTag(true);
    otherSpecifyCheckBox.setOutputMarkupPlaceholderTag(true);
    noneButtonLabel = new Label("noneButtonLabel", "NONE Button?: ");
    noneButtonModel = new Model();
    noneButtonModel.setObject(Boolean.FALSE);
    noneButtonCheckBox = new CheckBox("noneButtonField", noneButtonModel);
    form.add(noneButtonLabel);
    form.add(noneButtonCheckBox);
    noneButtonLabel.setOutputMarkupId(true);
    noneButtonCheckBox.setOutputMarkupId(true);
    noneButtonLabel.setOutputMarkupPlaceholderTag(true);
    noneButtonCheckBox.setOutputMarkupPlaceholderTag(true);
    noneButtonLabel.setVisible(false);
    noneButtonCheckBox.setVisible(false);

    // questionUseIfField = new TextField("questionUseIfField", new Model(""));
    // form.add(questionUseIfField);

    form.add(
        new AjaxFallbackButton("submitQuestion", form) {
          @Override
          public void onSubmit(AjaxRequestTarget target, Form form) {
            insertFormFieldsIntoQuestion(question);
            if (question.getId() == null) {
              List<Question> questions =
                  Questions.getQuestionsForStudy(question.getStudyId(), question.getType());
              questions.add(question);
              for (Integer i = 0; i < questions.size(); i++) {
                questions.get(i).setOrdering(i);
                DB.save(questions.get(i));
              }
            } else {
              DB.save(question);
            }
            form.setVisible(false);
            target.addComponent(parentThatNeedsUpdating);
            target.addComponent(form);
          }
        });
    add(form);

    setFormFieldsFromQuestion(question);
  }
Beispiel #11
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);
  }
  private void initLayout(
      final IModel<String> label, final String labelSize, final String textSize) {

    Label l = new Label(ID_LABEL, label);
    l.setVisible(getLabelVisibility());
    if (StringUtils.isNotEmpty(labelSize)) {
      l.add(AttributeAppender.prepend("class", labelSize));
    }
    add(l);

    WebMarkupContainer addFirstContainer = new WebMarkupContainer(ID_ADD_FIRST_CONTAINER);
    addFirstContainer.setOutputMarkupId(true);
    addFirstContainer.setOutputMarkupPlaceholderTag(true);
    addFirstContainer.add(
        new VisibleEnableBehaviour() {

          @Override
          public boolean isVisible() {
            return getModelObject().isEmpty();
          }
        });
    add(addFirstContainer);

    AjaxLink addFirst =
        new AjaxLink(ID_ADD_FIRST) {

          @Override
          public void onClick(AjaxRequestTarget target) {
            addFirstPerformed(target);
          }
        };
    addFirstContainer.add(addFirst);

    ListView repeater =
        new ListView<T>(ID_REPEATER, getModel()) {

          @Override
          protected void populateItem(final ListItem<T> listItem) {
            WebMarkupContainer textWrapper = new WebMarkupContainer(ID_TEXT_WRAPPER);
            textWrapper.add(
                AttributeAppender.prepend(
                    "class",
                    new AbstractReadOnlyModel<String>() {

                      @Override
                      public String getObject() {
                        StringBuilder sb = new StringBuilder();
                        if (StringUtils.isNotEmpty(textSize)) {
                          sb.append(textSize).append(' ');
                        }
                        if (listItem.getIndex() > 0 && StringUtils.isNotEmpty(getOffsetClass())) {
                          sb.append(getOffsetClass()).append(' ');
                          sb.append(CLASS_MULTI_VALUE);
                        }
                        return sb.toString();
                      }
                    }));
            listItem.add(textWrapper);

            TextField text = new TextField<>(ID_TEXT, createTextModel(listItem.getModel()));
            text.add(
                new AjaxFormComponentUpdatingBehavior("blur") {
                  @Override
                  protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {}
                });
            text.setEnabled(false);
            text.add(AttributeAppender.replace("placeholder", label));
            text.setLabel(label);
            textWrapper.add(text);

            FeedbackPanel feedback =
                new FeedbackPanel(ID_FEEDBACK, new ComponentFeedbackMessageFilter(text));
            textWrapper.add(feedback);

            WebMarkupContainer buttonGroup = new WebMarkupContainer(ID_BUTTON_GROUP);
            buttonGroup.add(
                AttributeAppender.append(
                    "class",
                    new AbstractReadOnlyModel<String>() {

                      @Override
                      public String getObject() {
                        if (listItem.getIndex() > 0 && StringUtils.isNotEmpty(labelSize)) {
                          return CLASS_MULTI_VALUE;
                        }

                        return null;
                      }
                    }));

            AjaxLink edit =
                new AjaxLink(ID_EDIT) {

                  @Override
                  public void onClick(AjaxRequestTarget target) {
                    editValuePerformed(target, listItem.getModel());
                  }
                };
            textWrapper.add(edit);

            listItem.add(buttonGroup);

            initButtons(buttonGroup, listItem);
          }
        };

    add(repeater);
  }
  private void constructPageComponent() {
    add(new FeedbackPanel("errorMessages"));

    errorMsg =
        new Label(
            "smsAuthenticationError", getLocalizer().getString("smsAuthentication.error", this));
    errorMsg.setVisible(false);
    errorMsg.setOutputMarkupId(true);
    errorMsg.setOutputMarkupPlaceholderTag(true);

    final WebMarkupContainer backDiv = new WebMarkupContainer("backDiv");
    backDiv.setOutputMarkupId(true);
    backDiv.setVisible(false);
    backDiv.setOutputMarkupPlaceholderTag(true);
    Form<?> backForm = new Form("backForm", new CompoundPropertyModel<SmsAuthenticationPage>(this));
    backForm.add(
        new Button("back") {
          @Override
          public void onSubmit() {
            // TODO
          }
        });
    backDiv.add(backForm);

    retryDiv = new WebMarkupContainer("retryDiv");
    retryDiv.setOutputMarkupId(true);
    retryDiv.setOutputMarkupPlaceholderTag(true);
    retryDiv.setVisible(false);
    Form<?> retryForm =
        new Form("retryForm", new CompoundPropertyModel<SmsAuthenticationPage>(this));
    retryForm.add(
        new Button("retry") {
          @Override
          public void onSubmit() {
            // TODO
          }
        });
    retryDiv.add(retryForm);

    cancelDiv = new WebMarkupContainer("cancelDiv");
    cancelDiv.setOutputMarkupId(true);
    cancelDiv.setOutputMarkupPlaceholderTag(true);
    cancelDiv.setVisible(false);
    Form<?> cancelForm =
        new Form("cancelForm", new CompoundPropertyModel<SmsAuthenticationPage>(this));
    cancelForm.add(
        new Button("cancel") {
          @Override
          public void onSubmit() {
            // TODO
          }
        }.setVisible(false));
    cancelDiv.add(cancelForm);

    final AbstractDefaultAjaxBehavior behave =
        new AbstractDefaultAjaxBehavior() {
          protected void respond(final AjaxRequestTarget target) {
            if (!isRedirected) {
              checkStatus(target);
            }
          }
        };
    add(behave);

    Form<?> ajaxForm =
        new Form("ajaxForm", new CompoundPropertyModel<SmsAuthenticationPage>(this)) {
          @Override
          protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            tag.put("action", behave.getCallbackUrl());
          }
        };
    add(errorMsg);
    add(backDiv);
    add(retryDiv);
    add(cancelDiv);
    add(ajaxForm);
  }