Java Code Examples for org.apache.wicket.markup.html.form.FormComponent#add()

The following examples show how to use org.apache.wicket.markup.html.form.FormComponent#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RatingFeatureEditor.java    From webanno with Apache License 2.0 6 votes vote down vote up
@Override
public void addFeatureUpdateBehavior()
{
    // Need to use a AjaxFormChoiceComponentUpdatingBehavior here since we use a RadioGroup
    // here.
    FormComponent focusComponent = getFocusComponent();
    focusComponent.add(new AjaxFormChoiceComponentUpdatingBehavior()
    {
        private static final long serialVersionUID = -5058365578109385064L;

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes aAttributes)
        {
            super.updateAjaxAttributes(aAttributes);
            addDelay(aAttributes, 300);
        }

        @Override
        protected void onUpdate(AjaxRequestTarget aTarget)
        {
            send(focusComponent, BUBBLE,
                    new FeatureEditorValueChangedEvent(RatingFeatureEditor.this, aTarget));
        }
    });
}
 
Example 2
Source File: FeatureEditor.java    From webanno with Apache License 2.0 6 votes vote down vote up
public void addFeatureUpdateBehavior()
{
    FormComponent focusComponent = getFocusComponent();
    focusComponent.add(new AjaxFormComponentUpdatingBehavior("change")
    {
        private static final long serialVersionUID = -8944946839865527412L;
        
        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes aAttributes)
        {
            super.updateAjaxAttributes(aAttributes);
            addDelay(aAttributes, 250);
        }
        
        @Override
        protected void onUpdate(AjaxRequestTarget aTarget)
        {
            send(focusComponent, BUBBLE,
                    new FeatureEditorValueChangedEvent(FeatureEditor.this, aTarget));
        }
    });
}
 
Example 3
Source File: WicketUtils.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Sets attribute size (only for TextFields) and style="length: width"; The width value is size + 0.5 em and for drop down choices size +
 * 2em;
 * @param component
 * @param size
 * @param important If true then "!important" is appended to the width style (true is default).
 * @return This for chaining.
 */
public static FormComponent< ? > setSize(final FormComponent< ? > component, final int size, final boolean important)
{
  if (component instanceof TextField) {
    component.add(AttributeModifier.replace("size", String.valueOf(size)));
  }
  final StringBuffer buf = new StringBuffer(20);
  buf.append("width: ");
  if (component instanceof DropDownChoice) {
    buf.append(size + 2).append("em");
  } else {
    buf.append(size).append(".5em");
  }
  if (important == true) {
    buf.append(" !important;");
  }
  buf.append(";");
  component.add(AttributeModifier.append("style", buf.toString()));
  return component;
}
 
Example 4
Source File: ComponentVisualErrorBehaviour.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Changes the CSS class of the linked {@link FormComponent} via AJAX.
 *
 * @param ajaxRequestTarget of type AjaxRequestTarget
 * @param valid Was the validation succesful?
 * @param cssClass The CSS class that must be set on the linked {@link FormComponent}
 */
private void changeCssClass(AjaxRequestTarget ajaxRequestTarget, boolean valid, String cssClass) {
    FormComponent formComponent = getFormComponent();

    if(formComponent.isValid() == valid){
        formComponent.add(new AttributeModifier("class", true, new Model("formInputField " + cssClass)));
        ajaxRequestTarget.add(formComponent);
    }

    if(updateComponent!=null){
        ajaxRequestTarget.add(updateComponent);
    }
}
 
Example 5
Source File: ComponentVisualErrorBehaviour.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Changes the CSS class of the linked {@link FormComponent} via AJAX.
 *
 * @param ajaxRequestTarget of type AjaxRequestTarget
 * @param valid Was the validation succesful?
 * @param cssClass The CSS class that must be set on the linked {@link FormComponent}
 */
private void changeCssClass(AjaxRequestTarget ajaxRequestTarget, boolean valid, String cssClass) {
    FormComponent formComponent = getFormComponent();

    if(formComponent.isValid() == valid){
        formComponent.add(new AttributeModifier("class", true, new Model("formInputField " + cssClass)));
        ajaxRequestTarget.add(formComponent);
    }

    if(updateComponent!=null){
        ajaxRequestTarget.add(updateComponent);
    }
}
 
Example 6
Source File: WicketUtils.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets readonly="readonly" and "readOnly" as class.
 * @param component
 * @return This for chaining.
 */
public static FormComponent< ? > setReadonly(final FormComponent< ? > component)
{
  component.add(AttributeModifier.append("class", "readonly"));
  component.add(AttributeModifier.replace("readonly", "readonly"));
  return component;
}
 
Example 7
Source File: AjaxMaxLengthEditableLabel.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @see org.apache.wicket.extensions.ajax.markup.html.AjaxEditableLabel#newEditor(org.apache.wicket.MarkupContainer, java.lang.String,
 *      org.apache.wicket.model.IModel)
 */
@Override
protected FormComponent<String> newEditor(final MarkupContainer parent, final String componentId, final IModel<String> model)
{
  final FormComponent<String> editor = super.newEditor(parent, componentId, model);
  editor.add(AttributeModifier.append("onkeypress", "if ( event.which == 13 ) { return false; }"));
  return editor;
}
 
Example 8
Source File: DefaultFocusFormVisitor.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
public void component(Component object, IVisit<Void> visit) {
	if (!visited.contains(object) && (object instanceof FormComponent) && !(object instanceof Button)) {
		final FormComponent<?> fc = (FormComponent<?>) object;
		visited.add(fc);
		if (!found && fc.isEnabled() && fc.isVisible()
				&& (fc instanceof DropDownChoice || fc instanceof AbstractTextComponent)) {
			found = true;
			fc.add(new DefaultFocusBehavior());
		}
	}
}
 
Example 9
Source File: WicketUtils.java    From projectforge-webapp with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Sets attribute size (only for TextFields) and style="width: x%";
 * @param component
 * @param size
 * @return This for chaining.
 */
public static FormComponent< ? > setPercentSize(final FormComponent< ? > component, final int size)
{
  component.add(AttributeModifier.append("style", "width: " + size + "%;"));
  return component;
}
 
Example 10
Source File: WicketUtils.java    From projectforge-webapp with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Sets attribute style="height: <height>ex;"
 * @param component
 * @param size
 * @return This for chaining.
 */
public static FormComponent< ? > setHeight(final FormComponent< ? > component, final int height)
{
  component.add(AttributeModifier.append("style", "height: " + height + "ex;"));
  return component;
}
 
Example 11
Source File: WicketUtils.java    From projectforge-webapp with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Adds class="focus" to the given component. It's evaluated by the adminica_ui.js. FocusOnLoadBehaviour doesn't work because the focus is
 * set to early (before the components are visible).
 * @param component
 * @return This for chaining.
 */
public static FormComponent< ? > setFocus(final FormComponent< ? > component)
{
  component.add(setFocus());
  return component;
}