@Override
  public void beforeRender(Component component) {
    this.statusModel.getObject();

    this.classNameModel.setObject(
        computeClass(this.statusModel.getObject(), this.mustBe, this.shouldBe));
    super.beforeRender(component);
  }
Ejemplo n.º 2
0
  @Override
  public void renderHead(Component component, IHeaderResponse response) {
    super.renderHead(component, response);

    response.render(
        JavaScriptHeaderItem.forScript(
            "function onClickAlert(text)\n {\n alert(text);\n }\n", getClass().getName()));
  }
  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);
  }