org.apache.wicket.markup.html.form.FormComponent Java Examples

The following examples show how to use org.apache.wicket.markup.html.form.FormComponent. 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: EmbeddedCollectionContainsFilterPanel.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public FormComponent<?> createFilterComponent(IModel<?> model) {
    OProperty property = getEntityModel().getObject();
    FormComponent<?> component;
    switch (property.getLinkedType()) {
        case BOOLEAN:
            component = new BooleanFilterPanel(getFilterId(), (IModel<Boolean>) model);
            break;
        case DATE:
            component = new BooleanFilterPanel(getFilterId(), (IModel<Boolean>) model);
            break;
        case DATETIME:
            component = new ODateField(getFilterId(), (IModel<Date>) model);
            break;
        default:
            component = new TextField<>(getFilterId(), model);
    }
    return component;
}
 
Example #2
Source File: BootstrapFeedbackPopover.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();

	filter = new IFeedbackMessageFilter() {
		private static final long serialVersionUID = -7726392072697648969L;

		public boolean accept(final FeedbackMessage msg) {
			Boolean b = visitChildren(FormComponent.class, new IVisitor<FormComponent<?>, Boolean>() {
				@Override
				public void component(FormComponent<?> arg0, IVisit<Boolean> arg1) {
					if (arg0.equals(msg.getReporter()))
						arg1.stop(true);
				}
			});

			if (b == null)
				return false;

			return b;
		}
	};

}
 
Example #3
Source File: BootstrapControlGroupFeedback.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void onConfigure() {
	super.onConfigure();
	
	filter = new IFeedbackMessageFilter() {
		private static final long serialVersionUID = -7726392072697648969L;

		public boolean accept(final FeedbackMessage msg) {
			Boolean b = visitChildren(FormComponent.class, new IVisitor<FormComponent<?>, Boolean>() {
				@Override
				public void component(FormComponent<?> arg0, IVisit<Boolean> arg1) {
					if (arg0.equals(msg.getReporter()))
						arg1.stop(true);
				}
			});

			if (b == null)
				return false;

			return b;
		}
	};
}
 
Example #4
Source File: AdvancedFormVisitor.java    From nextreports-server with Apache License 2.0 6 votes vote down vote up
public void component(FormComponent<?> object, IVisit<Void> visit) {
		Palette<?> palette = object.findParent(Palette.class);
		Component comp;
		if (palette != null) {
			comp = palette;
		} else {
			comp = object;
		}
		if (!visited.contains(comp))	{
			visited.add(comp);
			
			/*
			if (isValidComponent(c)) {
				AdvancedFormComponentLabel label = new AdvancedFormComponentLabel(getLabelId(c), c);
				c.getParent().add(label);
				c.setLabel(new Model<String>(c.getId()));
			}
			*/
			
//			c.setComponentBorder(new RequiredBorder());
			comp.add(new ValidationMessageBehavior());
			comp.add(new ErrorHighlightBehavior());
		}
	}
 
Example #5
Source File: ClassInCollectionFilterPanel.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@Override
public FormComponent<Collection<String>> createFilterComponent(IModel<?> model) {
    IModel<OClass> entityModel = getEntityModel();
    IModel<List<OClass>> classesModel = new SubClassesModel(entityModel, true, false);

    return new Select2MultiChoice<String>(getFilterId(), getModel(), new OClassCollectionTextChoiceProvider(classesModel)) {
        @Override
        protected void onInitialize() {
            super.onInitialize();
            getSettings()
                    .setWidth("100%")
                    .setCloseOnSelect(true)
                    .setTheme(BOOTSTRAP_SELECT2_THEME);
            add(new AjaxFormSubmitBehavior("change") {});
        }
    };
}
 
Example #6
Source File: TimeInputValidator.java    From nextreports-server with Apache License 2.0 6 votes vote down vote up
public void validate(Form form) {
	// we have a choice to validate the type converted values or the raw
	// input values, we validate the raw input
	final FormComponent formComponent1 = components[0];
	final FormComponent formComponent2 = components[1];

       String s1 = formComponent1.getInput();
       String s2 = formComponent2.getInput();

       if ((s1 == null) || (s2 == null) || "".equals(s1) || "".equals(s2)) {
           return;
       }

       if (comparator.compare(s1, s2) >= 0 ) {                        
           Map<String, Object> params = new HashMap<String, Object>();
           params.put("first", s1);
           params.put("second", s2);
           error(formComponent2, resourceKey(), params);
       }
}
 
Example #7
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 #8
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 #9
Source File: RangeFilterPanel.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public RangeFilterPanel(String id, IModel<List<T>> model, String filterId, IModel<OProperty> propertyModel,
                        IVisualizer visualizer, IFilterCriteriaManager manager) {
    super(id, model, filterId, propertyModel, visualizer, manager, Model.of(true));
    startComponent = (FormComponent<T>) createFilterComponent(Model.of());
    endComponent = (FormComponent<T>) createFilterComponent(Model.of());
    startComponent.setOutputMarkupId(true);
    endComponent.setOutputMarkupId(true);
    List<Component> rangeContainers = Lists.newArrayList();
    rangeContainers.add(getRangeContainer(startComponent, getFilterId(), true));
    rangeContainers.add(getRangeContainer(endComponent, getFilterId(), false));

    ListView<Component> listView = new ListView<Component>("rangeFilters", rangeContainers) {
        @Override
        protected void populateItem(ListItem<Component> item) {
            item.add(item.getModelObject());
        }
    };
    add(listView);
}
 
Example #10
Source File: PasswordValidator.java    From nextreports-server with Apache License 2.0 6 votes vote down vote up
public void validate(Form form) {
    // we have a choice to validate the type converted values or the raw
    // input values, we validate the raw input
    final FormComponent formComponent = components[0];

    String s = formComponent.getInput();

    if (s == null) {
        return;
    }

    s = passwordEncoder.encodePassword(s, null);

    try {            
        User user = securityService.getUserByName(NextServerSession.get().getUsername());
        if (!user.getPassword().equals(s)) {
            error(formComponent, resourceKey() + "." + "oldPasswordInvalid");
        }
    } catch (Exception e) {
        // TODO
        e.printStackTrace();
    }


}
 
Example #11
Source File: AbstractFieldsetPanel.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
public String getFormChildsFeedbackMessages(final boolean markAsRendered)
{
  if (hasFormChildsFeedbackMessage() == false) {
    return null;
  }
  final StringBuffer buf = new StringBuffer();
  boolean first = true;
  for (final FormComponent< ? > formComponent : allFormComponents) {
    if (formComponent.hasFeedbackMessage() == true) {
      final FeedbackMessage feedbackMessage = formComponent.getFeedbackMessages().first();
      if (markAsRendered == true) {
        feedbackMessage.markRendered();
      }
      first = StringHelper.append(buf, first, feedbackMessage.getMessage().toString(), "\n");
    }
  }
  return buf.toString();
}
 
Example #12
Source File: MinMaxPoolSizeValidator.java    From nextreports-server with Apache License 2.0 6 votes vote down vote up
public void validate(Form form) {
	// we have a choice to validate the type converted values or the raw
	// input values, we validate the raw input
	final FormComponent formComponent1 = components[0];
	final FormComponent formComponent2 = components[1];

       String s1 = formComponent1.getInput();
       String s2 = formComponent2.getInput();

       // disabled components
       if ( (s1 == null) || s1.trim().equals("") || (s2 == null) || s2.trim().equals("")) {
       	error(formComponent2, resourceKey() + "." + "notnull"); 
       }  else  {
       	Integer i1 = Integer.parseInt(s1);
       	Integer i2 = Integer.parseInt(s2);
       	if (i1.intValue() > i2.intValue()) {
       		error(formComponent2, resourceKey() + "." + "invalid");
       	}           
       }
}
 
Example #13
Source File: ValidationMsgBehavior.java    From wicket-spring-boot with Apache License 2.0 6 votes vote down vote up
@Override
public void afterRender(Component component) {
	FormComponent fc = (FormComponent) component;
	if (!fc.isValid()) {
		String error;
		if (fc.hasFeedbackMessage()) {
			FeedbackMessage first = fc.getFeedbackMessages().first();
			first.markRendered();
			error = first.getMessage().toString();
			
		} else {
			error = "Your input is invalid.";
		}
		fc.getResponse().write("*<span id=\"helpBlock2\" class=\"help-block\">"+error+"</span>");
		super.afterRender(component);
	}
}
 
Example #14
Source File: AbstractFieldsetPanel.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
private void checkLabelFor(final Component... components)
{
  if (labelFor == true) {
    return;
  }
  final Component component = components[0];
  if (component instanceof ComponentWrapperPanel) {
    this.label.add(AttributeModifier.replace("for", ((ComponentWrapperPanel) component).getComponentOutputId()));
    labelFor = true;
  }
  for (final Component comp : components) {
    if (comp instanceof LabeledWebMarkupContainer) {
      final LabeledWebMarkupContainer labeledComponent = (LabeledWebMarkupContainer) comp;
      if (labeledComponent.getLabel() == null) {
        labeledComponent.setLabel(new Model<String>(labelText));
      }
    } else if (component instanceof ComponentWrapperPanel) {
      final FormComponent<?> formComponent = ((ComponentWrapperPanel)component).getFormComponent();
      if (formComponent != null && formComponent.getLabel() == null) {
        formComponent.setLabel(new Model<String>(labelText));
      }
    }
  }
}
 
Example #15
Source File: DefaultFocusBehavior.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
@Override
public void bind(Component component) {
	if (!(component instanceof FormComponent)) {
		throw new IllegalArgumentException("DefaultFocusBehavior: component must be instanceof FormComponent");
	}
	component.setOutputMarkupId(true);
}
 
Example #16
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 #17
Source File: EqualsFilterPanel.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public FormComponent<?> createFilterComponent(IModel<?> model) {
    if (getEntityModel().getObject().getType() == OType.BOOLEAN) {
        return new BooleanFilterPanel(getFilterId(), (IModel<Boolean>) model);
    }
    return super.createFilterComponent(model);
}
 
Example #18
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 #19
Source File: InputChangeBehavior.java    From onedev with MIT License 5 votes vote down vote up
@Override
protected void onUpdate(AjaxRequestTarget target) {
	FormComponent<?> component = (FormComponent<?>) getComponent();

	// IE triggers "input" event when the focused on the search input even if nothing is 
	// input into search box yet. To work around this issue, we compare search string 
	// against previous value to only update the branches table if there is an actual 
	// change.
	String newInput = component.getInput();
	if (!Objects.equals(newInput, input)) {
		input = newInput;
		onInputChange(target);
	}
}
 
Example #20
Source File: EqualsFilterPanel.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public EqualsFilterPanel(String id, IModel<T> model, String filterId, IModel<OProperty> propertyModel,
                         IVisualizer visualizer,
                         IFilterCriteriaManager manager) {
    super(id, model, filterId, propertyModel, visualizer, manager, Model.of(true));
    add(formComponent = (FormComponent<T>) createFilterComponent(getModel()));
    formComponent.setOutputMarkupId(true);
}
 
Example #21
Source File: AddClusterModalPanel.java    From etcd-viewer with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeModalShow(AjaxRequestTarget target) {
    target.add(form);

    form.clearInput();

    form.visitFormComponents(new IVisitor<FormComponent<?>, Void>() {
        @Override
        public void component(FormComponent<?> object, IVisit<Void> visit) {
            if (object.hasFeedbackMessage()) {
                object.getFeedbackMessages().clear();
            }
        }
    });
}
 
Example #22
Source File: AbstractFieldsetPanel.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @return true if any form child has a feedback message.
 * @see org.apache.wicket.Component#hasFeedbackMessage()
 */
public boolean hasFormChildsFeedbackMessage()
{
  for (final FormComponent< ? > formComponent : allFormComponents) {
    if (formComponent.hasFeedbackMessage() == true) {
      return true;
    }
  }
  return false;
}
 
Example #23
Source File: WicketUtils.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static void setLabel(final FormComponent< ? > component, final Label label)
{
  final IModel<String> labelModel = (IModel<String>) label.getDefaultModel();
  if (component instanceof DatePanel) {
    ((DatePanel) component).getDateField().setLabel(labelModel);
  } else {
    component.setLabel(labelModel);
  }
}
 
Example #24
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 #25
Source File: EmbeddedCollectionEditPanel.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
protected void convertToData() {
	visitFormComponentsPostOrder(this, new IVisitor<FormComponent<?>, Void>() {

		@Override
		public void component(FormComponent<?> object,
				IVisit<Void> visit) {
			if(embeddedView != null && embeddedView.equals(object.getClass()))
			{
				object.convertInput();
				object.updateModel();
				visit.dontGoDeeper();
			}
		}
	});
}
 
Example #26
Source File: AbstractFieldsetPanel.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks all child form components and calls {@link FormComponent#isValid()}.
 * @return true if all childs are valid, otherwise false (if any child is invalid);
 */
public boolean isValid()
{
  for (final FormComponent< ? > formComponent : allFormComponents) {
    if (formComponent.isValid() == false) {
      return false;
    }
  }
  return true;
}
 
Example #27
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 #28
Source File: AbstractMetaPanel.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public V getEnteredValue()
{
	if(component instanceof FormComponent && ((FormComponent<V>)component).hasRawInput())
	{
		FormComponent<V> formComponent = (FormComponent<V>)component;
		convertInput(formComponent);
		return formComponent.getConvertedInput();
	}
	else
	{
		return getValueObject();
	}
}
 
Example #29
Source File: ShinyFormVisitor.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/** Avoid borders around components and child components. */
private boolean hasInvalidParent(final Component component)
{
  if (component == null) {
    return false;
  }
  if (component instanceof FieldsetPanel && ((FieldsetPanel) component).isValid() == false) {
    return true;
  }
  if (component instanceof FormComponent< ? > && ((FormComponent< ? >) component).isValid() == false) {
    return true;
  }
  return hasInvalidParent(component.getParent());
}
 
Example #30
Source File: MailServerValidator.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
public MailServerValidator(FormComponent[] formComponents) {
    if (formComponents == null) {
        throw new IllegalArgumentException("Invalid formComponents : null");
    }
    for (int i = 0, size = formComponents.length; i < size; i++) {
        if (formComponents[i] == null) {
            throw new IllegalArgumentException("argument formComponent" + i + " cannot be null");
        }
    }
    components = formComponents;
}