コード例 #1
0
    @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
ファイル: Image.java プロジェクト: tfreier/wicket
  /**
   * 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());
 }
コード例 #5
0
  /**
   * 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;
  }
コード例 #6
0
 @Override
 protected void onComponentTag(ComponentTag tag) {
   checkComponentTag(tag, "progress");
   super.onComponentTag(tag);
   tag.put("value", value.get());
   tag.put("max", max.get());
 }
コード例 #7
0
  /**
   * 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
ファイル: CheckGroup.java プロジェクト: hurrong/wicket
  @Override
  protected void onComponentTag(ComponentTag tag) {
    super.onComponentTag(tag);

    // No longer applicable, breaks XHTML validation.
    tag.remove("disabled");
    tag.remove("name");
  }
コード例 #9
0
 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
ファイル: YavBehavior.java プロジェクト: raduf/core
 /**
  * @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());
 }
コード例 #17
0
 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.");
   }
 }
コード例 #18
0
    /** {@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());
        }
      }
    }
コード例 #19
0
    @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);
    }
コード例 #20
0
 @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);
     }
   }
 }
コード例 #21
0
  @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
ファイル: YavBehavior.java プロジェクト: raduf/core
  /*
   * (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
ファイル: AjaxButton.java プロジェクト: JUGMadagascar/wicket
  @Override
  protected void onComponentTag(ComponentTag tag) {
    // WICKET-5594 prevent non-Ajax submit
    tag.put("type", "button");

    super.onComponentTag(tag);
  }
コード例 #26
0
  /**
   * 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);
  }
コード例 #27
0
 @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);
  }
コード例 #30
0
  @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());
  }