@Override
    public void onComponentTag(final Component component, final ComponentTag tag) {
      String expr = tag.getAttributes().getString(wicketMessageAttrName);
      if (!Strings.isEmpty(expr)) {
        expr = expr.trim();

        String[] attrsAndKeys = Strings.split(expr, ',');

        for (String attrAndKey : attrsAndKeys) {
          int colon = attrAndKey.lastIndexOf(":");
          // make sure the attribute-key pair is valid
          if (attrAndKey.length() < 3 || colon < 1 || colon > attrAndKey.length() - 2) {
            throw new WicketRuntimeException(
                "wicket:message attribute contains an invalid value [["
                    + expr
                    + "]], must be of form (attr:key)+");
          }

          String attr = attrAndKey.substring(0, colon);
          String key = attrAndKey.substring(colon + 1);

          // we need to call the proper getString() method based on
          // whether or not we have a default value
          final String value;
          if (tag.getAttributes().containsKey(attr)) {
            value = component.getString(key, null, tag.getAttributes().getString(attr));
          } else {
            value = component.getString(key);
          }
          tag.put(attr, value);
        }
      }
    }
Пример #2
0
  /**
   * Adds random noise to the url every request to prevent the browser from caching the image.
   *
   * @param tag
   */
  protected final void addAntiCacheParameter(final ComponentTag tag) {
    String url = tag.getAttributes().getString("src");
    url = url + (url.contains("?") ? "&" : "?");
    url = url + "antiCache=" + System.currentTimeMillis();

    tag.put("src", url);
  }
Пример #3
0
  /** @see org.apache.wicket.Component#onComponentTag(org.apache.wicket.markup.ComponentTag) */
  @Override
  protected void onComponentTag(ComponentTag tag) {
    super.onComponentTag(tag);

    checkComponentTag(tag, "label");

    LabeledWebMarkupContainer formComponent = getFormComponent();

    tag.put("for", formComponent.getMarkupId());

    if (formComponent instanceof FormComponent<?>) {
      FormComponent<?> fc = (FormComponent<?>) formComponent;

      if (fc.isRequired()) {
        tag.append("class", getString(REQUIRED_CSS_CLASS_KEY), " ");
      }
      if (fc.isValid() == false) {
        tag.append("class", getString(INVALID_CSS_CLASS_KEY), " ");
      }
    }

    if (formComponent.isEnabledInHierarchy() == false) {
      tag.append("class", getString(DISABLED_CSS_CLASS_KEY), " ");
    }

    // always transform the tag to <span></span> so even labels defined as <span/> render
    tag.setType(TagType.OPEN);
  }
Пример #4
0
 @Override
 public Component resolve(MarkupContainer container, MarkupStream markupStream, ComponentTag tag) {
   if (childId.equals(tag.getId())) {
     return childComponent;
   }
   return getEnclosureParent().get(tag.getId());
 }
  /**
   * Search the child's markup in the header section of the markup
   *
   * @param container
   * @param child
   * @return Null, if not found
   */
  public IMarkupFragment findMarkupInAssociatedFileHeader(
      final MarkupContainer container, final Component child) {
    // Get the associated markup
    IMarkupFragment markup = container.getAssociatedMarkup();
    IMarkupFragment childMarkup = null;

    // MarkupStream is good at searching markup
    MarkupStream stream = new MarkupStream(markup);
    while (stream.skipUntil(ComponentTag.class) && (childMarkup == null)) {
      ComponentTag tag = stream.getTag();
      if (TagUtils.isWicketHeadTag(tag)) {
        if (tag.getMarkupClass() == null) {
          // find() can still fail an return null => continue the search
          childMarkup = stream.getMarkupFragment().find(child.getId());
        }
      } else if (TagUtils.isHeadTag(tag)) {
        // find() can still fail an return null => continue the search
        childMarkup = stream.getMarkupFragment().find(child.getId());
      }

      // Must be a direct child. We are not interested in grand children
      if (tag.isOpen() && !tag.hasNoCloseTag()) {
        stream.skipToMatchingCloseTag(tag);
      }
      stream.next();
    }

    return childMarkup;
  }
 @Override
 protected void onComponentTag(ComponentTag tag) {
   checkComponentTag(tag, "progress");
   super.onComponentTag(tag);
   tag.put("value", value.get());
   tag.put("max", max.get());
 }
  /**
   * Renders head for embedded component, i.e. those who are not added directly to this container
   * but have the markup inside it.
   *
   * @param container The HtmlHeaderContainer
   */
  private void renderHeadForInnerSiblings(HtmlHeaderContainer container) {
    MarkupStream stream = new MarkupStream(getMarkup());

    while (stream.hasMore()) {
      MarkupElement childOpenTag = stream.nextOpenTag();

      if ((childOpenTag instanceof ComponentTag) && !stream.atCloseTag()) {
        // Get element as tag
        final ComponentTag tag = (ComponentTag) childOpenTag;

        // Get component id
        final String id = tag.getId();

        Component component = null;

        if (get(id) == null) {
          component = ComponentResolvers.resolveByComponentHierarchy(this, stream, tag);
        }

        if (component != null) {
          component.internalRenderHead(container);
        }

        // consider just direct children
        stream.skipToMatchingCloseTag(tag);
      }
    }
  }
Пример #8
0
  @Override
  protected void onComponentTag(ComponentTag tag) {
    super.onComponentTag(tag);

    // No longer applicable, breaks XHTML validation.
    tag.remove("disabled");
    tag.remove("name");
  }
 public static void addAttribute(ComponentTag tag, String attName, String addValue, String sep) {
   String value = tag.getAttributes().getString(attName);
   if (StringUtils.isEmpty(value)) {
     tag.put(attName, addValue);
   } else {
     tag.put(attName, value + sep + addValue);
   }
 }
Пример #10
0
 @Override
 protected void onComponentTag(final ComponentTag tag) {
   super.onComponentTag(tag);
   // our component tag is not actually the input that is submitted
   if (tag.getAttributes().containsKey("name")) {
     tag.remove("name");
   }
 }
Пример #11
0
 /** @see org.apache.wicket.markup.MarkupElement#equalTo(org.apache.wicket.markup.MarkupElement) */
 @Override
 public boolean equalTo(final MarkupElement element) {
   if (element instanceof ComponentTag) {
     final ComponentTag that = (ComponentTag) element;
     return getXmlTag().equalTo(that.getXmlTag());
   }
   return false;
 }
Пример #12
0
 @Override
 public void onComponentTag(ComponentTag tag) {
   // add onclick handler to the browser
   // if clicked in the browser, the function
   // click.response(AjaxRequestTarget target) is called on the server side
   tag.put("ondblclick", "Wicket.Ajax.get({'u':'" + click.getCallbackUrl() + "'})");
   tag.put("onclick", "Wicket.Ajax.get({'u':'" + click.getCallbackUrl() + "'})");
 }
Пример #13
0
 /**
  * Test that a null model does not append an empty attribute
  * https://issues.apache.org/jira/browse/WICKET-3884
  */
 @Test
 public void nullModelDoesNotAppendEmptyAttribute() {
   AttributeModifier appender = AttributeModifier.append("class", null);
   XmlTag xmlTag = new XmlTag();
   ComponentTag tag = new ComponentTag(xmlTag);
   appender.replaceAttributeValue(null, tag);
   Map<String, Object> attributes = tag.getAttributes();
   assertTrue(attributes.isEmpty());
 }
Пример #14
0
 /**
  * @param form
  * @param tag
  * @return
  */
 private String verifyFormName(Form<?> form, ComponentTag tag) {
   IValueMap attributes = tag.getAttributes();
   String value = attributes.getString("name");
   if (value == null) {
     value = form.getId();
     tag.put("name", value);
   }
   return value;
 }
Пример #15
0
 /**
  * Tests {@link AttributeModifier#remove(String)}
  *
  * <p>https://issues.apache.org/jira/browse/WICKET-3934
  */
 @Test
 public void removeAttribute() {
   AttributeModifier appender = AttributeModifier.remove("class");
   XmlTag xmlTag = new XmlTag();
   ComponentTag tag = new ComponentTag(xmlTag);
   Map<String, Object> attributes = tag.getAttributes();
   attributes.put("class", "someValue");
   appender.replaceAttributeValue(null, tag);
   assertTrue(attributes.isEmpty());
 }
Пример #16
0
 /** Test that a null model does not throw null pointers. */
 @Test
 public void nullModelDoesNotThrowNullPointerExceptions() {
   AttributeModifier modifier = new AttributeModifier("test", null);
   XmlTag xmlTag = new XmlTag();
   ComponentTag tag = new ComponentTag(xmlTag);
   tag.setId("foo");
   tag.setName("test");
   modifier.replaceAttributeValue(null, tag);
   Map<String, Object> attributes = tag.getAttributes();
   assertTrue(attributes.isEmpty());
 }
 protected void assertTagName(ComponentTag tag, String tagName) {
   if (!tagName.equalsIgnoreCase(tag.getName())) {
     throw new RuntimeException(
         getClass()
             + " can only be added to "
             + tagName
             + " tag but was added to "
             + tag.getName()
             + " tag.");
   }
 }
    /** {@inheritDoc} */
    @Override
    protected void onComponentTag(ComponentTag tag) {
      super.onComponentTag(tag);

      if (!isValid()) {
        tag.put("class", "imxt-invalid");
        FeedbackMessage message = getFeedbackMessages().first();
        if (message != null) {
          tag.put("title", message.getMessage().toString());
        }
      }
    }
    @Override
    public void onComponentTag(Component component, ComponentTag tag) {
      super.onComponentTag(component, tag);

      QuestionCategoryComponentsView view = (QuestionCategoryComponentsView) component;

      String cssClass = GRID_CLASS_PREFIX + "-" + view.getColumns();
      if (tag.getAttributes().containsKey("class")) {
        cssClass += " " + tag.getAttributes().getString("class");
      }
      tag.getAttributes().put("class", cssClass);
    }
 @Override
 public void onComponentTag(Component component, ComponentTag tag) {
   FormComponent<?> f = (FormComponent<?>) component;
   if (!f.isValid()) {
     String cl = tag.getAttribute("class");
     if (cl == null) {
       tag.put("class", "error");
     } else {
       tag.put("class", "error " + cl);
     }
   }
 }
  @Override
  protected void onComponentTag(ComponentTag tag) {
    super.onComponentTag(tag);

    if (isLinkEnabled()) {
      if (tag.getName().toLowerCase().equals("a")) {
        tag.put("href", "#");
      }
    } else {
      disableLink(tag);
    }
  }
Пример #22
0
 /**
  * Add an attribute with name equal (Object#equals()) to the special {@link
  * AttributeModifier#VALUELESS_ATTRIBUTE_REMOVE} but not identity equal
  *
  * <p>https://issues.apache.org/jira/browse/WICKET-3934
  */
 @Test
 public void appendSpecialAttribute() {
   String attrName = "attrName";
   AttributeModifier appender = AttributeModifier.append(attrName, "VA_REMOVE");
   XmlTag xmlTag = new XmlTag();
   ComponentTag tag = new ComponentTag(xmlTag);
   Map<String, Object> attributes = tag.getAttributes();
   attributes.put(attrName, "VA_REMOVE");
   appender.replaceAttributeValue(null, tag);
   assertFalse(attributes.isEmpty());
   assertEquals("VA_REMOVE VA_REMOVE", attributes.get(attrName));
 }
Пример #23
0
 /** Test simple model replacement. */
 @Test
 public void testModelReplacement() {
   AttributeModifier modifier = new AttributeModifier("test", Model.of("Ellioth Smith Rocks"));
   XmlTag xmlTag = new XmlTag();
   ComponentTag tag = new ComponentTag(xmlTag);
   tag.setId("test");
   tag.setName("id");
   modifier.replaceAttributeValue(null, tag);
   Map<String, Object> attributes = tag.getAttributes();
   assertTrue(!attributes.isEmpty());
   String replacement = (String) attributes.get("test");
   assertNotNull(replacement);
   assertEquals("Ellioth Smith Rocks", replacement);
 }
Пример #24
0
  /*
   * (non-Javadoc)
   *
   * @see org.apache.wicket.behavior.Behavior#onComponentTag(org.apache.wicket.Component,
   * org.apache.wicket.markup.ComponentTag)
   */
  @Override
  public void onComponentTag(Component component, ComponentTag tag) {
    super.onComponentTag(component, tag);

    if (!Form.class.isAssignableFrom(component.getClass())) {
      throw new WicketRuntimeException("This behavior is only applicable on a Form component");
    }

    Form<?> form = (Form<?>) component;

    // Retrieve and set form name
    String formName = verifyFormName(form, tag);

    tag.put("onsubmit", "return yav.performCheck('" + formName + "', rules);");

    // Open the Yav script (inlined JavaScript)
    AppendingStringBuffer buffer = new AppendingStringBuffer("<script>\n");
    buffer.append("var rules=new Array();\n");

    // Visit all form components and check for validators (and write the
    // appropriate Yav rules in the current inlined JavaScript)
    form.visitFormComponents(new YavFormComponentVisitor(buffer, form));

    // Build the call to the yav.init with the proper form name
    buffer.append("function yavInit() {\n");
    buffer.append("    yav.init('" + formName + "', rules);\n");
    buffer.append("}\n");

    // Close the Yav script
    buffer.append("</script>\n");

    // Write the generated script into the response
    Response response = RequestCycle.get().getResponse();
    response.write(buffer.toString());
  }
Пример #25
0
  @Override
  protected void onComponentTag(ComponentTag tag) {
    // WICKET-5594 prevent non-Ajax submit
    tag.put("type", "button");

    super.onComponentTag(tag);
  }
  /**
   * Handle tag &lt;wicket:header-items&gt;
   *
   * @param tag
   */
  private void handleHeaderItemsTag(ComponentTag tag) {
    if (foundHeaderItemsTag) {
      throw new MarkupException(
          new MarkupStream(markup),
          "More than one <wicket:header-items/> detected in the <head> element. Only one is allowed.");
    } else if (foundClosingHead) {
      throw new MarkupException(
          new MarkupStream(markup),
          "Detected <wicket:header-items/> after the closing </head> element.");
    }

    foundHeaderItemsTag = true;
    tag.setId(HEADER_ID);
    tag.setAutoComponentTag(true);
    tag.setModified(true);
  }
 @Override
 protected void onComponentTag(ComponentTag tag) {
   if (style != null && !"null".equals(style)) {
     tag.put("style", style);
   }
   super.onComponentTag(tag);
 }
Пример #28
0
  /** @see Component#onComponentTag(ComponentTag) */
  @Override
  protected void onComponentTag(final ComponentTag tag) {

    tag.put("value", getDefaultModelObjectAsString());

    super.onComponentTag(tag);
  }
Пример #29
0
  /* (non-Javadoc)
   * @see net.jawr.web.wicket.AbstractJawrReference#createRenderer(net.jawr.web.resource.bundle.handler.ResourceBundlesHandler, boolean, org.apache.wicket.markup.ComponentTag)
   */
  @Override
  protected BundleRenderer createRenderer(
      ResourceBundlesHandler rsHandler, Boolean useRandomParam, ComponentTag tag) {

    final IValueMap attributes = tag.getAttributes();
    boolean defer = attributes.getBoolean(JawrConstant.DEFER_ATTR);
    return new JavascriptHTMLBundleLinkRenderer(rsHandler, useRandomParam, defer);
  }
  @Override
  public void onComponentTag(Component component, ComponentTag tag) {
    super.onComponentTag(component, tag);

    IValueMap attributes = tag.getAttributes();
    attributes.put("data-header-selector", "#" + header.getMarkupId());
    attributes.put("data-footer-selector", "#" + footer.getMarkupId());
  }