Search in sources :

Example 41 with TextField

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

the class OnChangeAjaxBehavior method updateAjaxAttributes.

@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);
    Component component = getComponent();
    // all the other components will use just 'change'
    if (!(component instanceof TextField || component instanceof TextArea)) {
        attributes.setEventNames(EVENT_CHANGE);
    }
}
Also used : TextArea(org.apache.wicket.markup.html.form.TextArea) TextField(org.apache.wicket.markup.html.form.TextField) Component(org.apache.wicket.Component) FormComponent(org.apache.wicket.markup.html.form.FormComponent)

Example 42 with TextField

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

the class WicketTesterTest method executeAjaxEvent_ajaxFormSubmitLink.

/**
 * Test that the executeAjaxEvent "submits" the form if the event is a AjaxFormSubmitBehavior.
 */
@Test
public void executeAjaxEvent_ajaxFormSubmitLink() {
    tester.startPage(MockPageWithFormAndAjaxFormSubmitBehavior.class);
    // Get the page
    MockPageWithFormAndAjaxFormSubmitBehavior page = (MockPageWithFormAndAjaxFormSubmitBehavior) tester.getLastRenderedPage();
    Pojo pojo = page.getPojo();
    assertEquals("Mock name", pojo.getName());
    TextField<?> name = (TextField<?>) tester.getComponentFromLastRenderedPage("form:name");
    assertEquals("Mock name", name.getValue());
    assertFalse(page.isExecuted());
    tester.getRequest().getPostParameters().setParameterValue(name.getInputName(), "Mock name");
    // Execute the ajax event
    tester.executeAjaxEvent(MockPageWithFormAndAjaxFormSubmitBehavior.EVENT_COMPONENT, "click");
    assertTrue("AjaxFormSubmitBehavior.onSubmit() has not been executed in " + MockPageWithFormAndAjaxFormSubmitBehavior.class, page.isExecuted());
    assertEquals("Mock name", ((TextField<?>) tester.getComponentFromLastRenderedPage("form:name")).getValue());
    // The name of the pojo should still be the same. If the
    // executeAjaxEvent weren't submitting the form the name would have been
    // reset to null, because the form would have been updated but there
    // wouldn't be any data to update it with.
    assertNotNull("executeAjaxEvent() did not properly submit the form", pojo.getName());
    assertEquals("Mock name", pojo.getName());
}
Also used : Pojo(org.apache.wicket.util.tester.MockPageWithFormAndAjaxFormSubmitBehavior.Pojo) TextField(org.apache.wicket.markup.html.form.TextField) Test(org.junit.Test)

Example 43 with TextField

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

the class AuthorizationTest method testEnabledDisallowedComponent.

/**
 * Test that a component will update it's model when authorization is ok.
 *
 * @throws Exception
 */
@Test
public void testEnabledDisallowedComponent() throws Exception {
    tester.getApplication().getSecuritySettings().setAuthorizationStrategy(new IAuthorizationStrategy.AllowAllAuthorizationStrategy() {

        /**
         * @see org.apache.wicket.authorization.IAuthorizationStrategy#isActionAuthorized(org.apache.wicket.Component,
         *      org.apache.wicket.authorization.Action)
         */
        @Override
        public boolean isActionAuthorized(Component c, Action action) {
            if (action == Component.ENABLE && c instanceof TextField && c.getId().equals("stringInput")) {
                return false;
            }
            return true;
        }
    });
    tester.startPage(AuthTestPage1.class);
    tester.assertRenderedPage(AuthTestPage1.class);
    tester.getRequest().getPostParameters().setParameterValue("form:stringInput", "test");
    try {
        tester.submitForm("form");
        Component component = tester.getComponentFromLastRenderedPage("form:stringInput");
        assertEquals("", component.getDefaultModelObjectAsString());
    } catch (WicketRuntimeException e) {
    // good
    }
}
Also used : Action(org.apache.wicket.authorization.Action) TextField(org.apache.wicket.markup.html.form.TextField) IAuthorizationStrategy(org.apache.wicket.authorization.IAuthorizationStrategy) WebComponent(org.apache.wicket.markup.html.WebComponent) IRequestableComponent(org.apache.wicket.request.component.IRequestableComponent) Test(org.junit.Test)

Example 44 with TextField

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

the class TextFormGroup method initLayout.

private void initLayout(IModel<String> label, final String tooltipKey, String labelCssClass, String textCssClass, final boolean required, final boolean markAsRequired, boolean isSimilarAsPropertyPanel) {
    WebMarkupContainer labelContainer = new WebMarkupContainer(ID_LABEL_CONTAINER);
    add(labelContainer);
    Label l = new Label(ID_LABEL, label);
    if (StringUtils.isNotEmpty(labelCssClass)) {
        labelContainer.add(AttributeAppender.prepend("class", labelCssClass));
    }
    if (isSimilarAsPropertyPanel) {
        labelContainer.add(AttributeAppender.prepend("class", " col-xs-2 prism-property-label "));
    } else {
        labelContainer.add(AttributeAppender.prepend("class", " control-label "));
    }
    labelContainer.add(l);
    Label tooltipLabel = new Label(ID_TOOLTIP, new Model<>());
    tooltipLabel.add(new AttributeAppender("data-original-title", new IModel<String>() {

        @Override
        public String getObject() {
            return getString(tooltipKey);
        }
    }));
    tooltipLabel.add(new InfoTooltipBehavior());
    tooltipLabel.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return tooltipKey != null;
        }
    });
    tooltipLabel.setOutputMarkupId(true);
    tooltipLabel.setOutputMarkupPlaceholderTag(true);
    labelContainer.add(tooltipLabel);
    WebMarkupContainer requiredContainer = new WebMarkupContainer(ID_REQUIRED);
    requiredContainer.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return markAsRequired;
        }
    });
    labelContainer.add(requiredContainer);
    WebMarkupContainer propertyLabel = new WebMarkupContainer(ID_PROPERTY_LABEL);
    WebMarkupContainer rowLabel = new WebMarkupContainer(ID_ROW);
    WebMarkupContainer textWrapper = new WebMarkupContainer(ID_TEXT_WRAPPER);
    if (StringUtils.isNotEmpty(textCssClass)) {
        textWrapper.add(AttributeAppender.prepend("class", textCssClass));
    }
    if (isSimilarAsPropertyPanel) {
        propertyLabel.add(AttributeAppender.prepend("class", " col-md-10 prism-property-value "));
        rowLabel.add(AttributeAppender.prepend("class", " row "));
    }
    propertyLabel.add(rowLabel);
    rowLabel.add(textWrapper);
    add(propertyLabel);
    TextField text = createText(getModel(), label, required);
    text.setLabel(label);
    textWrapper.add(text);
    FeedbackPanel feedback = new FeedbackPanel(ID_FEEDBACK, new ContainerFeedbackMessageFilter(this));
    feedback.setOutputMarkupId(true);
    textWrapper.add(feedback);
}
Also used : InfoTooltipBehavior(com.evolveum.midpoint.web.util.InfoTooltipBehavior) IModel(org.apache.wicket.model.IModel) FeedbackPanel(org.apache.wicket.markup.html.panel.FeedbackPanel) Label(org.apache.wicket.markup.html.basic.Label) TextField(org.apache.wicket.markup.html.form.TextField) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) ContainerFeedbackMessageFilter(org.apache.wicket.feedback.ContainerFeedbackMessageFilter) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Example 45 with TextField

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

the class MultiValueChoosePanel method initLayout.

private void initLayout(final IModel<List<T>> chosenValues, final List<PrismReferenceValue> filterValues, final boolean required, final boolean multiselect) {
    AjaxLink<String> addButton = new AjaxLink<String>(ID_ADD_BUTTON) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            editValuePerformed(chosenValues.getObject(), filterValues, target, multiselect);
        }
    };
    addButton.setOutputMarkupPlaceholderTag(true);
    add(addButton);
    ListView<T> selectedRowsList = new ListView<T>(ID_SELECTED_ROWS, chosenValues) {

        @Override
        protected void populateItem(ListItem<T> item) {
            WebMarkupContainer textWrapper = new WebMarkupContainer(ID_TEXT_WRAPPER);
            textWrapper.setOutputMarkupPlaceholderTag(true);
            // was value
            TextField<String> text = new TextField<>(ID_TEXT, createTextModel(item.getModel()));
            text.add(new AjaxFormComponentUpdatingBehavior("blur") {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
                }
            });
            text.setRequired(required);
            text.setEnabled(false);
            text.setOutputMarkupPlaceholderTag(true);
            textWrapper.add(text);
            FeedbackPanel feedback = new FeedbackPanel(ID_FEEDBACK, new ComponentFeedbackMessageFilter(text));
            feedback.setOutputMarkupPlaceholderTag(true);
            textWrapper.add(feedback);
            initButtons(item, item);
            item.add(textWrapper);
        }
    };
    selectedRowsList.setReuseItems(true);
    add(selectedRowsList);
}
Also used : AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ComponentFeedbackMessageFilter(org.apache.wicket.feedback.ComponentFeedbackMessageFilter) FeedbackPanel(org.apache.wicket.markup.html.panel.FeedbackPanel) ListView(org.apache.wicket.markup.html.list.ListView) TextField(org.apache.wicket.markup.html.form.TextField) ListItem(org.apache.wicket.markup.html.list.ListItem) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink)

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