Package org.apache.wicket.util.string

Examples of org.apache.wicket.util.string.AppendingStringBuffer


      {
        option = getLocalizer().getString("nullValid", this, "");
      }

      // The <option> tag buffer
      final AppendingStringBuffer buffer = new AppendingStringBuffer(64 + option.length());

      // Add option tag
      buffer.append("\n<option");

      // If null is selected, indicate that
      if (selected == noSelectionValue)
      {
        buffer.append(" selected=\"selected\"");
      }

      // Add body of option tag
      buffer.append(" value=\"" + noSelectionValue + "\">")
        .append(option)
        .append("</option>");
      return buffer;
    }
    else
View Full Code Here


  {
    // Iterate through choices
    final List<? extends T> choices = getChoices();

    // Buffer to hold generated body
    final AppendingStringBuffer buffer = new AppendingStringBuffer(70 * (choices.size() + 1));

    // Value of this choice
    final String selected = getValue();

    // Loop through choices
View Full Code Here

  {
    // Iterate through choices
    final List<? extends T> choices = getChoices();

    // Buffer to hold generated body
    final AppendingStringBuffer buffer = new AppendingStringBuffer((choices.size() + 1) * 70);

    // The selected value
    final String selected = getValue();

    // Loop through choices
    for (int index = 0; index < choices.size(); index++)
    {
      // Get next choice
      final T choice = choices.get(index);

      Object displayValue = getChoiceRenderer().getDisplayValue(choice);
      Class<?> objectClass = (displayValue == null ? null : displayValue.getClass());

      // Get label for choice
      String label = "";

      if (objectClass != null && objectClass != String.class)
      {
        final IConverter converter = getConverter(objectClass);
        label = converter.convertToString(displayValue, getLocale());
      }
      else if (displayValue != null)
      {
        label = displayValue.toString();
      }

      // If there is a display value for the choice, then we know that the
      // choice is automatic in some way. If label is /null/ then we know
      // that the choice is a manually created radio tag at some random
      // location in the page markup!
      if (label != null)
      {
        // Append option suffix
        buffer.append(getPrefix());

        String id = getChoiceRenderer().getIdValue(choice, index);
        final String idAttr = getMarkupId() + "-" + id;

        boolean enabled = isEnabledInHierarchy() && !isDisabled(choice, index, selected);

        // Add radio tag
        buffer.append("<input name=\"")
          .append(getInputName())
          .append("\"")
          .append(" type=\"radio\"")
          .append((isSelected(choice, index, selected) ? " checked=\"checked\"" : ""))
          .append((enabled ? "" : " disabled=\"disabled\""))
          .append(" value=\"")
          .append(id)
          .append("\" id=\"")
          .append(idAttr)
          .append("\"");

        // Should a roundtrip be made (have onSelectionChanged called)
        // when the option is clicked?
        if (wantOnSelectionChangedNotifications())
        {
          CharSequence url = urlFor(IOnChangeListener.INTERFACE);

          Form<?> form = findParent(Form.class);
          if (form != null)
          {
            buffer.append(" onclick=\"")
              .append(form.getJsForInterfaceUrl(url))
              .append(";\"");
          }
          else
          {
            // NOTE: do not encode the url as that would give
            // invalid JavaScript
            buffer.append(" onclick=\"window.location.href='")
              .append(url)
              .append((url.toString().indexOf('?') > -1 ? "&" : "?") + getInputName())
              .append("=")
              .append(id)
              .append("';\"");
          }
        }

        // Allows user to add attributes to the <input..> tag
        {
          IValueMap attrs = getAdditionalAttributes(index, choice);
          if (attrs != null)
          {
            for (Map.Entry<String, Object> attr : attrs.entrySet())
            {
              buffer.append(" ")
                .append(attr.getKey())
                .append("=\"")
                .append(attr.getValue())
                .append("\"");
            }
          }
        }

        if (getApplication().getDebugSettings().isOutputComponentPath())
        {
          String path = getPageRelativePath();
          path = path.replace("_", "__");
          path = path.replace(":", "_");
          buffer.append(" wicketpath=\"")
            .append(path)
            .append("_input_")
            .append(index)
            .append("\"");
        }

        buffer.append("/>");

        // Add label for radio button
        String display = label;
        if (localizeDisplayValues())
        {
          display = getLocalizer().getString(label, this, label);
        }

        CharSequence escaped = display;
        if (getEscapeModelStrings())
        {
          escaped = Strings.escapeMarkup(display);
        }

        buffer.append("<label for=\"")
          .append(idAttr)
          .append("\">")
          .append(escaped)
          .append("</label>");

        // Append option suffix
        buffer.append(getSuffix());
      }
    }

    // Replace body
    replaceComponentTagBody(markupStream, openTag, buffer);
View Full Code Here

   */
  @Override
  public final String getModelValue()
  {
    final Collection<T> selectedValues = getModelObject();
    final AppendingStringBuffer buffer = new AppendingStringBuffer();
    if (selectedValues != null)
    {
      final List<? extends T> choices = getChoices();
      for (T object : selectedValues)
      {
        int index = choices.indexOf(object);
        buffer.append(getChoiceRenderer().getIdValue(object, index));
        buffer.append(VALUE_SEPARATOR);
      }
    }
    return buffer.toString();
  }
View Full Code Here

   */
  @Override
  public void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag)
  {
    List<? extends E> choices = getChoices();
    final AppendingStringBuffer buffer = new AppendingStringBuffer((choices.size() * 50) + 16);
    final String selected = getValue();

    // Append default option
    buffer.append(getDefaultChoice(selected));

    for (int index = 0; index < choices.size(); index++)
    {
      final E choice = choices.get(index);
      appendOptionHtml(buffer, choice, index, selected);
    }

    buffer.append("\n");
    replaceComponentTagBody(markupStream, openTag, buffer);
  }
View Full Code Here

  protected CharSequence getEventHandler()
  {
    final String formId = getForm().getMarkupId();
    final CharSequence url = getCallbackUrl();

    AppendingStringBuffer call = new AppendingStringBuffer("wicketSubmitFormById('").append(
      formId)
      .append("', '")
      .append(url)
      .append("', ");

    if (getComponent() instanceof IFormSubmittingComponent)
    {
      call.append("'")
        .append(((IFormSubmittingComponent)getComponent()).getInputName())
        .append("' ");
    }
    else
    {
      call.append("null");
    }

    return generateCallbackScript(call) + ";";
  }
View Full Code Here

   */
  public String getErrorMessage(final Throwable throwable)
  {
    if (throwable != null)
    {
      AppendingStringBuffer sb = new AppendingStringBuffer(256);

      // first print the last cause
      List<Throwable> al = convertToList(throwable);
      int length = al.size() - 1;
      Throwable cause = al.get(length);
      sb.append("Last cause: ").append(cause.getMessage()).append('\n');
      if (throwable instanceof WicketRuntimeException)
      {
        String msg = throwable.getMessage();
        if (throwable instanceof MarkupException)
        {
          MarkupStream stream = ((MarkupException)throwable).getMarkupStream();
          if (stream != null)
          {
            String text = "\n" + stream.toString();
            if (msg.endsWith(text))
            {
              msg = msg.substring(0, msg.length() - text.length());
            }
          }
        }

        sb.append("WicketMessage: ");
        sb.append(msg);
        sb.append("\n\n");
      }
      return sb.toString();
    }
    else
    {
      return "[Unknown]";
    }
View Full Code Here

  {
    if (throwable != null)
    {
      List<Throwable> al = convertToList(throwable);

      AppendingStringBuffer sb = new AppendingStringBuffer(256);

      // first print the last cause
      int length = al.size() - 1;
      Throwable cause = al.get(length);

      sb.append("Root cause:\n\n");
      outputThrowable(cause, sb, false);

      if (length > 0)
      {
        sb.append("\n\nComplete stack:\n\n");
        for (int i = 0; i < length; i++)
        {
          outputThrowable(al.get(i), sb, true);
          sb.append("\n");
        }
      }
      return sb.toString();
    }
    else
    {
      return "<Null Throwable>";
    }
View Full Code Here

    renderer.setBaseUrl(action);
    url = renderer.renderUrl(Url.parse(url.toString()));
    renderer.setBaseUrl(oldBase);

    Form<?> root = getRootForm();
    return new AppendingStringBuffer("document.getElementById('").append(
      root.getHiddenFieldId())
      .append("').value='")
      .append(url)
      .append("';document.getElementById('")
      .append(root.getMarkupId())
View Full Code Here

   */
  protected void appendDefaultButtonField(final MarkupStream markupStream,
    final ComponentTag openTag)
  {

    AppendingStringBuffer buffer = new AppendingStringBuffer();

    // div that is not visible (but not display:none either)
    buffer.append(HIDDEN_DIV_START);

    // add an empty textfield (otherwise IE doesn't work)
    buffer.append("<input type=\"text\" autocomplete=\"false\"/>");

    // add the submitting component
    final Component submittingComponent = (Component)defaultSubmittingComponent;
    buffer.append("<input type=\"submit\" name=\"");
    buffer.append(defaultSubmittingComponent.getInputName());
    buffer.append("\" onclick=\" var b=document.getElementById('");
    buffer.append(submittingComponent.getMarkupId());
    buffer.append("'); if (b!=null&amp;&amp;b.onclick!=null&amp;&amp;typeof(b.onclick) != 'undefined') {  var r = b.onclick.bind(b)(); if (r != false) b.click(); } else { b.click(); };  return false;\" ");
    buffer.append(" />");

    // close div
    buffer.append("</div>");

    getResponse().write(buffer);
  }
View Full Code Here

TOP

Related Classes of org.apache.wicket.util.string.AppendingStringBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.