Example usage for org.apache.wicket.markup.html.form FormComponent getValue

List of usage examples for org.apache.wicket.markup.html.form FormComponent getValue

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.form FormComponent getValue.

Prototype

public final String getValue() 

Source Link

Document

Gets current value for a form component, which can be either input data entered by the user, or the component's model object if no input was provided.

Usage

From source file:com.servoy.j2db.server.headlessclient.dataui.FocusIfInvalidAttributeModifier.java

License:Open Source License

public FocusIfInvalidAttributeModifier(final FormComponent component) {
    // please keep the case in the event name
    super("onblur", true, new Model<String>() //$NON-NLS-1$
    {//from   w  w w .j a  v a  2s. com
        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            Object mo = component.getModelObject();
            String value;
            if (mo instanceof Boolean) {
                value = mo.toString();
            } else {
                value = '\'' + String.valueOf(Strings.escapeMarkup(component.getValue())) + '\'';
                value = component.getValue();
                if (value == null) {
                    value = ""; //$NON-NLS-1$
                } else {
                    value = '\'' + Strings.escapeMarkup(value).toString() + '\'';
                }
            }
            return "scheduleRequestFocusOnInvalid(\"" + component.getMarkupId() + "\", \"" + value + "\");"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        }
    });
}

From source file:nl.knaw.dans.common.wicket.util.RequireExactlyOneValidator.java

License:Apache License

/**
 * Validate the form.//w  ww.j  a  v  a  2  s  . c  o  m
 * 
 * @param form The form to validate.
 * @see org.apache.wicket.markup.html.form.validation.IFormValidator#validate(org.apache.wicket.markup.html.form.Form)
 */
public void validate(Form form) {
    int nrFilledFields = 0;

    for (FormComponent component : this.dependentComponents) {
        if (component.getValue().trim().length() > 0) {
            nrFilledFields++;
        }
    }

    if (nrFilledFields != 1) {
        error(this.dependentComponents[0]);
    }
}

From source file:nl.knaw.dans.common.wicket.util.RequireOneValidator.java

License:Apache License

/**
 * Validate the form./*from  www.  ja  va2s.c o  m*/
 * 
 * @param form The form to validate.
 * @see org.apache.wicket.markup.html.form.validation.IFormValidator#validate(org.apache.wicket.markup.html.form.Form)
 */
public void validate(Form form) {
    boolean anyNotEmpty = false;

    // Check content size for every component
    for (FormComponent component : this.dependentComponents) {
        if (component.getValue().trim().length() > 0) {
            anyNotEmpty = true;
            break;
        }
    }

    // If every component is empty
    if (!anyNotEmpty) {
        error(this.dependentComponents[0]);
    }
}

From source file:org.artifactory.common.wicket.util.ComponentPersister.java

License:Open Source License

/**
 * Override wicket's cookie utils to enable encoding and decoding of cookie content.
 * See RTFACT-6086/* w w  w.j a  v  a  2 s . c om*/
 * @param formComponent
 * @return
 */
protected static void save(final FormComponent<?> formComponent) {
    String key = formComponent.getPageRelativePath();
    String value = formComponent.getValue();
    try {
        COOKIE_UTILS.save(key, URLEncoder.encode(value, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        log.debug("Failed to encode cookie value: {}", e.getMessage());
        COOKIE_UTILS.save(key, value);
    }
}

From source file:org.artifactory.webapp.wicket.page.config.services.cron.CronNextDatePanel.java

License:Open Source License

public CronNextDatePanel(String id, final FormComponent cronExpField) {
    super(id);//  w ww  .j  a  v  a 2  s . co  m

    String nextRun = getNextRunTime(cronExpField.getValue());
    final Label nextRunLabel = new Label("cronExpNextRun", nextRun);
    nextRunLabel.setOutputMarkupId(true);
    add(nextRunLabel);

    // send ajax request with only cronExpField
    BaseTitledLink calculateButton = new BaseTitledLink("calculate", "Refresh");
    calculateButton.add(new JavascriptEvent("onclick", new AbstractReadOnlyModel() {
        @Override
        public Object getObject() {
            return "dojo.byId('" + cronExpField.getMarkupId() + "').onchange();";
        }
    }));
    add(calculateButton);

    // update nextRunLabel on cronExpField change
    cronExpField.setOutputMarkupId(true);
    cronExpField.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            nextRunLabel.setDefaultModelObject(getNextRunTime(cronExpField.getValue()));
            target.add(nextRunLabel);
        }

        @Override
        protected void onError(AjaxRequestTarget target, RuntimeException e) {
            super.onError(target, e);
            nextRunLabel.setDefaultModelObject(getNextRunTime(cronExpField.getValue()));
            target.add(nextRunLabel);
        }

        @Override
        protected IAjaxCallDecorator getAjaxCallDecorator() {
            return new NoAjaxIndicatorDecorator();
        }
    });
}

From source file:org.geoserver.web.data.store.pgraster.PGRasterCoverageStoreEditPanel.java

License:Open Source License

public PGRasterCoverageStoreEditPanel(final String componentId, final Form storeEditForm) {
    super(componentId, storeEditForm);

    final IModel model = storeEditForm.getModel();
    setDefaultModel(model);/* w w w .jav  a2s .  c  om*/
    final IModel paramsModel = new PropertyModel(model, "connectionParameters");

    // double container dance to get stuff to show up and hide on demand (grrr)
    final WebMarkupContainer configsContainer = new WebMarkupContainer("configsContainer");
    configsContainer.setOutputMarkupId(true);
    add(configsContainer);

    final PGRasterPanel advancedConfigPanel = new PGRasterPanel("pgpanel", paramsModel, storeEditForm);
    advancedConfigPanel.setOutputMarkupId(true);
    advancedConfigPanel.setVisible(false);
    configsContainer.add(advancedConfigPanel);

    // TODO: Check whether this constructor is properly setup
    final TextParamPanel url = new TextParamPanel("urlPanel", new PropertyModel(paramsModel, "URL"),
            new ResourceModel("url", "URL"), true);
    final FormComponent urlFormComponent = url.getFormComponent();
    urlFormComponent.add(new FileExistsValidator());
    add(url);

    // enabled flag, and show the rest only if enabled is true
    IModel<Boolean> enabledModel = new Model<Boolean>(false);
    enabled = new CheckBox("enabled", enabledModel);
    add(enabled);
    enabled.add(new AjaxFormComponentUpdatingBehavior("onclick") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            Boolean visible = enabled.getModelObject();

            advancedConfigPanel.setVisible(visible);
            target.addComponent(configsContainer);
        }
    });

    /*
     * Listen to form submission and update the model's URL
     */
    storeEditForm.add(new IFormValidator() {
        private static final long serialVersionUID = 1L;

        public FormComponent[] getDependentFormComponents() {
            if (enabled.getModelObject()) {
                return advancedConfigPanel.getDependentFormComponents();
            } else {
                return new FormComponent[] { urlFormComponent };
            }
        }

        public void validate(final Form form) {
            CoverageStoreInfo storeInfo = (CoverageStoreInfo) form.getModelObject();
            String coverageUrl = urlFormComponent.getValue();
            if (enabled.getModelObject()) {
                coverageUrl = advancedConfigPanel.buildURL() + coverageUrl;
            }

            storeInfo.setURL(coverageUrl);
        }

    });
}

From source file:org.geoserver.web.GeoServerWicketTestSupport.java

License:Open Source License

public void prefillForm(final FormTester tester) {
    Form form = tester.getForm();//from  ww  w. ja va  2s  .  c o m
    form.visitChildren(new Component.IVisitor() {

        public Object component(Component component) {
            if (component instanceof FormComponent) {
                FormComponent fc = (FormComponent) component;
                String name = fc.getInputName();
                String value = fc.getValue();

                tester.setValue(name, value);
            }
            return Component.IVisitor.CONTINUE_TRAVERSAL;
        }
    });
}

From source file:org.hippoecm.frontend.plugins.standardworkflow.RenameDocumentDialogTest.java

License:Apache License

@Test
public void dialogCreatedContainingExpectedInputValues() throws Exception {
    final FormTester formTester = createDialog(false);
    FormComponent<String> nameComponent = (FormComponent<String>) formTester.getForm().get(NAME_INPUT);
    assertNotNull(nameComponent);/* ww  w  .  j a  v  a  2 s .  c o  m*/
    assertEquals("News", nameComponent.getValue());

    FormComponent<String> urlField = (FormComponent<String>) formTester.getForm().get(URL_INPUT);
    assertNotNull(urlField);
    assertEquals("news", urlField.getValue());

    // url field is editable in renaming dialog
    assertTrue(urlField.isEnabled());

    // the urlAction must be 'Reset'
    Label urlActionLabel = (Label) formTester.getForm().get("name-url:uriAction:uriActionLabel");
    assertNotNull(urlActionLabel);
    assertEquals("Reset", urlActionLabel.getDefaultModelObject());
}

From source file:org.wicketstuff.scriptaculous.autocomplete.AjaxAutocompleteBehavior.java

License:Apache License

@Override
protected void respond(AjaxRequestTarget target) {
    FormComponent formComponent = (FormComponent) getComponent();

    formComponent.validate();//from   ww  w . j ava  2  s  .co m
    if (formComponent.isValid()) {
        formComponent.updateModel();
    }
    String input = formComponent.getValue();
    RequestCycle.get()
            .setRequestTarget(new StringRequestTarget(formatResultsAsUnorderedList(getResults(input))));
}

From source file:sf.wicklet.wicketext.test.MarkupBuilder01Test.java

License:Apache License

@Test
public void simpletest02() {
    final int[] count = { 0 };
    @SuppressWarnings("serial")
    final SimpleTest02Page testpage = new SimpleTest02Page() {
        @Override/*w w  w  .j av  a 2  s  .c  o  m*/
        protected void onSubmit() {
            ++count[0];
            final IRequestParameters params = getRequest().getPostParameters();
            Assert.assertEquals(SimpleTest02Page.class.getName(), params.getParameterValue("input").toString());
            @SuppressWarnings("unchecked")
            final FormComponent<String> c = (FormComponent<String>) form.get("input");
            Assert.assertEquals(SimpleTest02Page.class.getName(), c.getValue());
        }
    };
    final Page page = tester.startPage(testpage);
    tester.assertRenderedPage(SimpleTest02Page.class);
    final FormTester formtester = tester.newFormTester("form", false);
    formtester.setValue("input", SimpleTest02Page.class.getName());
    formtester.submit("submit");
    Assert.assertEquals(0, page.getFeedbackMessages().size());
    Assert.assertEquals(1, count[0]);
}