Search in sources :

Example 6 with TextField

use of org.apache.wicket.markup.html.form.TextField in project midpoint by Evolveum.

the class AssociationValueChoicePanel method initLayout.

private void initLayout(final IModel<PrismContainerValue<ShadowAssociationType>> value, final List<PrismPropertyValue> values, final boolean required, Class<C> type) {
    WebMarkupContainer textWrapper = new WebMarkupContainer(ID_TEXT_WRAPPER);
    textWrapper.setOutputMarkupId(true);
    TextField<String> text = new TextField<>(ID_TEXT, createTextModel(value));
    text.add(new AjaxFormComponentUpdatingBehavior("blur") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
        }
    });
    text.setRequired(required);
    text.setEnabled(false);
    textWrapper.add(text);
    FeedbackPanel feedback = new FeedbackPanel(ID_FEEDBACK, new ComponentFeedbackMessageFilter(text));
    feedback.setFilter(new ComponentFeedbackMessageFilter(text));
    textWrapper.add(feedback);
    AjaxLink edit = new AjaxLink(ID_EDIT) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            editValuePerformed(target);
        }
    };
    edit.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return model.getObject().isEmpty();
        }
    });
    textWrapper.add(edit);
    add(textWrapper);
    initDialog(type, values);
}
Also used : AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ComponentFeedbackMessageFilter(org.apache.wicket.feedback.ComponentFeedbackMessageFilter) FeedbackPanel(org.apache.wicket.markup.html.panel.FeedbackPanel) TextField(org.apache.wicket.markup.html.form.TextField) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer)

Example 7 with TextField

use of org.apache.wicket.markup.html.form.TextField in project wicket by apache.

the class CookieUtilsTest method test1.

/**
 * @throws Exception
 */
@SuppressWarnings({ "unchecked" })
@Test
public void test1() throws Exception {
    // How does the test work: Make sure you have a page, form and form component properly set
    // up (getRelativePath() etc.). See #before().
    final Page page = tester.getLastRenderedPage();
    // Get the form and form component created
    final TestForm form = (TestForm) page.get("form");
    final TextField<String> textField = (TextField<String>) form.get("input");
    // Right after init, the requests and responses cookie lists must be empty
    assertEquals(0, getRequestCookies().size());
    assertEquals(0, getResponseCookies().size());
    // Create a persister for the test
    final CookieUtils persister = new CookieUtils();
    // See comment in CookieUtils on how removing a Cookies works. As no cookies in the request,
    // no "delete" cookie will be added to the response.
    persister.remove(textField);
    assertEquals(0, getRequestCookies().size());
    assertEquals(0, getResponseCookies().size());
    // Save the input field's value (add it to the response's cookie list)
    persister.save(textField);
    assertTrue(getRequestCookies().isEmpty());
    assertEquals(1, getResponseCookies().size());
    assertEquals("test", (getResponseCookies().get(0)).getValue());
    assertEquals("form.input", (getResponseCookies().get(0)).getName());
    assertEquals(tester.getRequest().getContextPath() + tester.getRequest().getServletPath(), (getResponseCookies().get(0)).getPath());
    // To remove a cookie means to add a cookie with maxAge=0. Provided a cookie with the same
    // name has been provided in the request. Thus, no changes in our test case
    persister.remove(textField);
    assertEquals(0, getRequestCookies().size());
    assertEquals(1, getResponseCookies().size());
    assertEquals("test", (getResponseCookies().get(0)).getValue());
    assertEquals("form.input", (getResponseCookies().get(0)).getName());
    assertEquals(tester.getRequest().getContextPath() + tester.getRequest().getServletPath(), (getResponseCookies().get(0)).getPath());
    // Try to load it. Because there is no Cookie matching the textfield's name the model's
    // value remains unchanged
    persister.load(textField);
    assertEquals("test", textField.getDefaultModelObjectAsString());
    // Simulate loading a textfield. Initialize textfield with a new (default) value, copy the
    // cookie from response to request (simulating a browser), than load the textfield from
    // cookie and voala the textfield's value should change.
    // save means: add it to the response
    // load means: take it from request
    assertEquals("test", textField.getDefaultModelObjectAsString());
    textField.setDefaultModelObject("new text");
    assertEquals("new text", textField.getDefaultModelObjectAsString());
    copyCookieFromResponseToRequest();
    assertEquals(1, getRequestCookies().size());
    assertEquals(1, getResponseCookies().size());
    persister.load(textField);
    assertEquals("test", textField.getDefaultModelObjectAsString());
    assertEquals(1, getRequestCookies().size());
    assertEquals(1, getResponseCookies().size());
    // remove all cookies from mock response. Because I'll find the cookie to be removed in the
    // request, the persister will create a "delete" cookie to remove the cookie on the client
    // and add it to the response. The already existing Cookie from the previous test gets
    // removed from response since it is the same.
    persister.remove(textField);
    assertEquals(1, getRequestCookies().size());
    assertEquals(1, getResponseCookies().size());
    assertEquals("form.input", (getResponseCookies().get(0)).getName());
    assertEquals(0, (getResponseCookies().get(0)).getMaxAge());
}
Also used : TextField(org.apache.wicket.markup.html.form.TextField) Page(org.apache.wicket.Page) TestForm(org.apache.wicket.util.cookies.CookieValuePersisterTestPage.TestForm) Test(org.junit.Test)

Example 8 with TextField

use of org.apache.wicket.markup.html.form.TextField in project wicket by apache.

the class TestHomePage method testWithBorder2.

@Test
public void testWithBorder2() {
    tester.startPage(HomePage.class);
    tester.assertRenderedPage(HomePage.class);
    FormTester formTester = tester.newFormTester("border:form");
    // formTester.setValue("..:textfield1", "testxxx");
    @SuppressWarnings("unchecked") TextField<String> textfield = (TextField<String>) tester.getLastRenderedPage().get("border:form:body:textfield");
    tester.getRequest().getPostParameters().setParameterValue(textfield.getInputName(), "abcde");
    MyTextField datefield = (MyTextField) tester.getLastRenderedPage().get("border:form:body:datefield");
    tester.getRequest().getPostParameters().setParameterValue(datefield.getInputName(), "aaabbb");
    MyDateField datefield2 = (MyDateField) tester.getLastRenderedPage().get("border:form:body:datefield2");
    @SuppressWarnings("unchecked") TextField<String> date = (TextField<String>) datefield2.get("date");
    tester.getRequest().getPostParameters().setParameterValue(date.getInputName(), "abcdef");
    formTester.submit();
    tester.assertNoErrorMessage();
    HomePage page = (HomePage) tester.getLastRenderedPage();
    assertEquals("abcde", page.getTextfield());
    assertEquals("aaabbb-converted", page.getDatefield());
    assertEquals("abcdef-converted", page.getDatefield2());
    assertEquals("abcde", page.get("border:form:body:lbltextfield").getDefaultModelObjectAsString());
    assertEquals("aaabbb-converted", page.get("border:form:body:lbldatefield").getDefaultModelObjectAsString());
    assertEquals("abcdef-converted", page.get("border:form:body:lbldatefield2").getDefaultModelObjectAsString());
}
Also used : FormTester(org.apache.wicket.util.tester.FormTester) TextField(org.apache.wicket.markup.html.form.TextField) Test(org.junit.Test)

Example 9 with TextField

use of org.apache.wicket.markup.html.form.TextField in project wicket by apache.

the class TestHomePage method testWithBorder2.

@Test
public void testWithBorder2() {
    FormTester formTester = tester.newFormTester("border:form");
    // formTester.setValue("..:textfield1", "testxxx");
    @SuppressWarnings("unchecked") TextField<String> textfield = (TextField<String>) tester.getLastRenderedPage().get("border:form:border_body:textfield");
    tester.getRequest().getPostParameters().setParameterValue(textfield.getInputName(), "abcde");
    MyTextField datefield = (MyTextField) tester.getLastRenderedPage().get("border:form:border_body:datefield");
    tester.getRequest().getPostParameters().setParameterValue(datefield.getInputName(), "aaabbb");
    MyDateField datefield2 = (MyDateField) tester.getLastRenderedPage().get("border:form:border_body:datefield2");
    @SuppressWarnings("unchecked") TextField<String> date = (TextField<String>) datefield2.get("date");
    tester.getRequest().getPostParameters().setParameterValue(date.getInputName(), "abcdef");
    formTester.submit();
    tester.assertNoErrorMessage();
    HomePage page = (HomePage) tester.getLastRenderedPage();
    assertEquals("abcde", page.getTextfield());
    assertEquals("aaabbb-converted", page.getDatefield());
    assertEquals("abcdef-converted", page.getDatefield2());
    assertEquals("abcde", page.get("border:form:border_body:lbltextfield").getDefaultModelObjectAsString());
    assertEquals("aaabbb-converted", page.get("border:form:border_body:lbldatefield").getDefaultModelObjectAsString());
    assertEquals("abcdef-converted", page.get("border:form:border_body:lbldatefield2").getDefaultModelObjectAsString());
}
Also used : FormTester(org.apache.wicket.util.tester.FormTester) TextField(org.apache.wicket.markup.html.form.TextField) Test(org.junit.Test)

Example 10 with TextField

use of org.apache.wicket.markup.html.form.TextField in project wicket by apache.

the class AddressFormPanel method setupPanel.

private void setupPanel() {
    // create the form and add the fields and submit button
    Form<ChildModel> form = new Form<ChildModel>("childForm", getModel()) {

        @Override
        protected void onValidateModelObjects() {
            super.onValidateModelObjects();
            getModelObject().setChildValidated(true);
        }
    };
    add(form);
    // add all the form fields
    form.add(new TextField("address1"));
    form.add(new TextField("address2"));
    form.add(new TextField("city"));
    form.add(new TextField("state"));
    form.add(new TextField("zip"));
    // add the child submit button
    add(new AjaxSubmitLink("childSubmitButton", form) {

        @Override
        public void onSubmit(AjaxRequestTarget target) {
            getPanelInstance().getModelObject().submittedCalled(target);
        }
    });
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Form(org.apache.wicket.markup.html.form.Form) TextField(org.apache.wicket.markup.html.form.TextField) AjaxSubmitLink(org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink)

Aggregations

TextField (org.apache.wicket.markup.html.form.TextField)61 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)37 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)30 Label (org.apache.wicket.markup.html.basic.Label)25 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)20 AjaxFormComponentUpdatingBehavior (org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior)20 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)18 ListItem (org.apache.wicket.markup.html.list.ListItem)15 ListView (org.apache.wicket.markup.html.list.ListView)15 IModel (org.apache.wicket.model.IModel)14 ArrayList (java.util.ArrayList)13 PropertyModel (org.apache.wicket.model.PropertyModel)13 ComponentFeedbackMessageFilter (org.apache.wicket.feedback.ComponentFeedbackMessageFilter)11 DropDownChoice (org.apache.wicket.markup.html.form.DropDownChoice)11 FeedbackPanel (org.apache.wicket.markup.html.panel.FeedbackPanel)11 List (java.util.List)10 CheckBox (org.apache.wicket.markup.html.form.CheckBox)10 InfoTooltipBehavior (com.evolveum.midpoint.web.util.InfoTooltipBehavior)9 Form (org.apache.wicket.markup.html.form.Form)9 EmptyOnBlurAjaxFormUpdatingBehaviour (com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour)6