예제 #1
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);
  }
예제 #2
0
  /** loads a form from an xml file and registeres it with the controller. */
  public Component createComponent(RequestContext context) throws JspException {
    try {

      Document doc = parseDocument(context, getXmlUri());

      // find the bean model
      Object bean = null;
      if (model != null) bean = context.getModelReference(model);

      // create the component
      FormComponent fc = createFormComponent(context, id, doc, bean);
      fc.setBookmarkable(bookmarkable);
      fc.setFinishButton(finishButton);

      registerWithWizard(fc);
      return fc;

    } catch (MalformedURLException e) {
      logger.error(null, e);
      throw new JspException(e);
    }
  }
예제 #3
0
 /**
  * Convert the input respecting the flag convertEmptyInputStringToNull. Subclasses that override
  * this method should test this flag also.
  *
  * @see org.apache.wicket.markup.html.form.FormComponent#convertInput()
  */
 @Override
 protected void convertInput() {
   // Stateless forms don't have to be rendered first, convertInput could be called before
   // onBeforeRender calling resolve type here again to check if the type is correctly set.
   resolveType();
   String[] value = getInputAsArray();
   String tmp = value != null && value.length > 0 ? value[0] : null;
   if (getConvertEmptyInputStringToNull() && Strings.isEmpty(tmp)) {
     setConvertedInput(null);
   } else {
     super.convertInput();
   }
 }
예제 #4
0
  /**
   * Processes the component tag.
   *
   * @param tag Tag to modify
   * @see org.apache.wicket.Component#onComponentTag(ComponentTag)
   */
  @Override
  protected void onComponentTag(final ComponentTag tag) {
    checkComponentTag(tag, "input");
    checkComponentTagAttribute(tag, "type", "checkbox");

    final String value = getValue();
    final IConverter<Boolean> converter = getConverter(Boolean.class);
    final Boolean checked = converter.convertToObject(value, getLocale());

    if (Boolean.TRUE.equals(checked)) {
      tag.put("checked", "checked");
    } else {
      // In case the attribute was added at design time
      tag.remove("checked");
    }

    // remove value attribute, because it overrides the browser's submitted value, eg a [input
    // type="checkbox" value=""] will always submit as false
    tag.remove("value");

    // Should a roundtrip be made (have onSelectionChanged called) when the
    // checkbox is clicked?
    if (wantOnSelectionChangedNotifications()) {
      CharSequence url = urlForListener(new PageParameters());

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

    super.onComponentTag(tag);
  }
예제 #5
0
 /**
  * See {@link FormComponent#updateCollectionModel(FormComponent)} for details on how the model is
  * updated.
  */
 @Override
 public void updateModel() {
   FormComponent.updateCollectionModel(this);
 }
예제 #6
0
 /**
  * If the type is not set try to guess it if the model supports it.
  *
  * @see org.apache.wicket.Component#onBeforeRender()
  */
 @Override
 protected void onBeforeRender() {
   super.onBeforeRender();
   resolveType();
 }