Example usage for org.apache.wicket.ajax AjaxRequestTarget add

List of usage examples for org.apache.wicket.ajax AjaxRequestTarget add

Introduction

In this page you can find the example usage for org.apache.wicket.ajax AjaxRequestTarget add.

Prototype

void add(Component... components);

Source Link

Document

Adds components to the list of components to be rendered.

Usage

From source file:br.com.oak.wicket.ui.behavior.ComponentVisualErrorBehavior.java

License:Open Source License

/**
 * 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}
 *///from  ww w. j  av a 2 s .c  om
private void changeCssClass(AjaxRequestTarget ajaxRequestTarget, boolean valid, String cssClass) {

    FormComponent<?> formComponent = (FormComponent<?>) getFormComponent();

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

    if (updateComponent != null) {
        ajaxRequestTarget.add(updateComponent);
    }
}

From source file:by.grodno.ss.rentacar.webapp.page.admin.panel.UserEditPanel.java

@Override
public void onInitialize() {
    super.onInitialize();
    UserEditPanel.this.setOutputMarkupId(true);

    Form<UserProfile> form = new Form<UserProfile>("form", new CompoundPropertyModel<UserProfile>(userProfile));

    TextField<String> created = new TextField<String>("created");
    created.setEnabled(false);// ww  w. j  a  v  a  2  s.co  m
    form.add(created);

    TextField<String> email = new TextField<String>("email", new PropertyModel<>(userCredentials, "email"));
    email.setRequired(true);
    email.add(StringValidator.maximumLength(100));
    email.add(StringValidator.minimumLength(3));
    email.add(EmailAddressValidator.getInstance());
    form.add(email);

    DropDownChoice<UserRole> roleDropDown = new DropDownChoice<>("role",
            new PropertyModel<>(userCredentials, "role"), Arrays.asList(UserRole.values()),
            UserRoleChoiceRenderer.INSTANCE);
    roleDropDown.setRequired(true);
    form.add(roleDropDown);

    TextField<String> firstName = new TextField<String>("firstName");
    firstName.setRequired(true);
    firstName.add(StringValidator.maximumLength(100));
    firstName.add(StringValidator.minimumLength(2));
    firstName.add(new PatternValidator("[A-Za-z]+"));
    form.add(firstName);

    TextField<String> lastName = new TextField<String>("lastName");
    lastName.setRequired(true);
    lastName.add(StringValidator.maximumLength(100));
    lastName.add(StringValidator.minimumLength(2));
    lastName.add(new PatternValidator("[A-Za-z]+"));
    form.add(lastName);

    TextField<String> phone = new TextField<String>("phoneNumber");
    phone.setRequired(true);
    phone.add(StringValidator.maximumLength(100));
    phone.add(StringValidator.minimumLength(2));
    phone.add(new PatternValidator("[0-9+()-]+"));
    form.add(phone);

    TextField<String> licNumber = new TextField<String>("licenseNumber");
    licNumber.add(StringValidator.maximumLength(100));
    licNumber.add(StringValidator.minimumLength(2));
    licNumber.add(new PatternValidator("[A-Za-z0-9]+"));
    form.add(licNumber);

    DateTextFieldConfig config = new DateTextFieldConfig();
    config.withLanguage(AuthorizedSession.get().getLocale().getLanguage());
    config.withFormat("dd.MM.yyyy");
    DateTextField dateBirth = new DateTextField("birthDay", config);
    form.add(dateBirth);

    TextField<String> address = new TextField<String>("address");
    address.add(StringValidator.maximumLength(100));
    address.add(StringValidator.minimumLength(2));
    address.add(new PatternValidator("[A-Za-z0-9 /-]+"));
    form.add(address);

    TextField<String> city = new TextField<String>("city");
    city.add(StringValidator.maximumLength(100));
    city.add(StringValidator.minimumLength(2));
    city.add(new PatternValidator("[A-Za-z0-9]+"));
    form.add(city);

    TextField<String> region = new TextField<String>("region");
    region.add(StringValidator.maximumLength(100));
    region.add(StringValidator.minimumLength(2));
    region.add(new PatternValidator("[A-Za-z0-9]+"));
    form.add(region);

    TextField<String> zip = new TextField<String>("zipCode");
    zip.add(StringValidator.maximumLength(20));
    zip.add(StringValidator.minimumLength(2));
    zip.add(new PatternValidator("[0-9]+"));
    form.add(zip);

    WebMarkupContainer passTable = new WebMarkupContainer("pass-table");
    passTable.setOutputMarkupId(true);

    WebMarkupContainer trPass = new WebMarkupContainer("pass");
    WebMarkupContainer trCpass = new WebMarkupContainer("cpass");
    if (userProfile.getId() == null) {
        trPass.setVisible(true);
        trCpass.setVisible(true);
    } else {
        trPass.setVisible(false);
        trCpass.setVisible(false);
    }
    trPass.setOutputMarkupId(true);
    trCpass.setOutputMarkupId(true);

    PasswordTextField password = new PasswordTextField("password",
            new PropertyModel<>(userCredentials, "password"));
    trPass.add(password);
    PasswordTextField cpassword = new PasswordTextField("cpassword", Model.of(""));
    trCpass.add(cpassword);

    passTable.add(trPass);
    passTable.add(trCpass);
    form.add(passTable);
    form.add(new EqualPasswordInputValidator(password, cpassword));

    AjaxLink<Void> changePass = new AjaxLink<Void>("change-password") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            if (!trPass.isVisible()) {
                trPass.setVisible(true);
                trCpass.setVisible(true);
                passTable.add(trPass);
                passTable.add(trCpass);
            } else {
                trPass.setVisible(false);
                trCpass.setVisible(false);
            }
            if (target != null) {
                target.add(passTable);
            }
        }
    };
    if (userProfile.getId() == null) {
        changePass.setVisible(false);
    }
    form.add(changePass);

    form.add(new SubmitLink("save") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onSubmit() {
            if (userProfile.getId() == null) {
                userService.register(userProfile, userCredentials);
            } else {
                userService.update(userProfile);
                userService.update(userCredentials);
            }
            info("User was saved");
        }
    });

    boolean a = (AuthorizedSession.get().isSignedIn()
            && AuthorizedSession.get().getLoggedUser().getRole().equals(UserRole.ADMIN));
    form.setEnabled(a);
    add(form);

    add(new AjaxLink<Void>("back") {
        private static final long serialVersionUID = 1L;

        public void onClick(AjaxRequestTarget target) {
            Component newPanel = new UserListPanel(UserEditPanel.this.getId(), filter);
            UserEditPanel.this.replaceWith(newPanel);
            if (target != null) {
                target.add(newPanel);
            }
        }
    });
}

From source file:by.grodno.ss.rentacar.webapp.page.MyBooking.ProfileEditPanel.java

@Override
public void onInitialize() {
    super.onInitialize();
    final NotificationPanel feedback = new NotificationPanel("feedbackpanel");
    add(feedback);/* www . j  a v  a 2s.  c o m*/

    Form<UserProfile> form = new Form<UserProfile>("form", new CompoundPropertyModel<UserProfile>(userProfile));

    TextField<String> firstName = new TextField<String>("firstName");
    firstName.setRequired(true);
    firstName.add(StringValidator.maximumLength(100));
    firstName.add(StringValidator.minimumLength(2));
    firstName.add(new PatternValidator("[A-Za-z]+"));
    form.add(firstName);

    TextField<String> lastName = new TextField<String>("lastName");
    lastName.setRequired(true);
    lastName.add(StringValidator.maximumLength(100));
    lastName.add(StringValidator.minimumLength(2));
    lastName.add(new PatternValidator("[A-Za-z]+"));
    form.add(lastName);

    TextField<String> phone = new TextField<String>("phoneNumber");
    phone.setRequired(true);
    phone.add(StringValidator.maximumLength(100));
    phone.add(StringValidator.minimumLength(2));
    phone.add(new PatternValidator("[0-9+()-]+"));
    form.add(phone);

    TextField<String> licNumber = new TextField<String>("licenseNumber");
    licNumber.add(StringValidator.maximumLength(100));
    licNumber.add(StringValidator.minimumLength(2));
    licNumber.add(new PatternValidator("[A-Za-z0-9]+"));
    form.add(licNumber);

    DateTextFieldConfig config = new DateTextFieldConfig();
    config.withLanguage(AuthorizedSession.get().getLocale().getLanguage());
    config.withFormat("dd.MM.yyyy");
    DateTextField dateBirth = new DateTextField("birthDay", config);
    form.add(dateBirth);

    TextField<String> address = new TextField<String>("address");
    address.add(StringValidator.maximumLength(100));
    address.add(StringValidator.minimumLength(2));
    address.add(new PatternValidator("[A-Za-z0-9 /-]+"));
    form.add(address);

    TextField<String> city = new TextField<String>("city");
    city.add(StringValidator.maximumLength(100));
    city.add(StringValidator.minimumLength(2));
    city.add(new PatternValidator("[A-Za-z0-9]+"));
    form.add(city);

    TextField<String> region = new TextField<String>("region");
    region.add(StringValidator.maximumLength(100));
    region.add(StringValidator.minimumLength(2));
    region.add(new PatternValidator("[A-Za-z0-9]+"));
    form.add(region);

    TextField<String> zip = new TextField<String>("zipCode");
    zip.add(StringValidator.maximumLength(20));
    zip.add(StringValidator.minimumLength(2));
    zip.add(new PatternValidator("[0-9]+"));
    form.add(zip);

    Label email = new Label("email", new PropertyModel<>(userCredentials, "email"));
    form.add(email);

    WebMarkupContainer passTable = new WebMarkupContainer("pass-table");
    passTable.setOutputMarkupId(true);

    WebMarkupContainer trPass = new WebMarkupContainer("pass");
    WebMarkupContainer trCpass = new WebMarkupContainer("cpass");
    if (userProfile.getId() == null) {
        trPass.setVisible(true);
        trCpass.setVisible(true);
    } else {
        trPass.setVisible(false);
        trCpass.setVisible(false);
    }
    trPass.setOutputMarkupId(true);
    trCpass.setOutputMarkupId(true);

    PasswordTextField password = new PasswordTextField("password",
            new PropertyModel<>(userCredentials, "password"));
    trPass.add(password);
    PasswordTextField cpassword = new PasswordTextField("cpassword", Model.of(""));
    trCpass.add(cpassword);

    passTable.add(trPass);
    passTable.add(trCpass);
    form.add(passTable);
    form.add(new EqualPasswordInputValidator(password, cpassword));

    AjaxLink<Void> changePass = new AjaxLink<Void>("change-password") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            if (!trPass.isVisible()) {
                trPass.setVisible(true);
                trCpass.setVisible(true);
                passTable.add(trPass);
                passTable.add(trCpass);
            } else {
                trPass.setVisible(false);
                trCpass.setVisible(false);
            }
            if (target != null) {
                target.add(passTable);
            }
        }
    };
    if (userProfile.getId() == null) {
        changePass.setVisible(false);
    }
    form.add(changePass);

    form.add(new SubmitLink("save") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onSubmit() {
            if (userProfile.getId() == null) {
                error("saving error");
            } else {
                userService.update(userProfile);
                userService.update(userCredentials);
            }
            info("User was saved");
        }
    });
    add(form);

    add(new Link<Void>("back") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            setResponsePage(new MyBookingPage());
        }
    });
}

From source file:by.parfen.disptaxi.webapp.etc.ChoicePage.java

License:Apache License

/**
 * Constructor./*ww  w  .  j  av  a 2  s .  c om*/
 */
public ChoicePage() {
    final City city = cityService.get(15L);
    List<Street> streetsList;
    streetsList = streetService.getAllByCity(city);
    for (Street streetItem : streetsList) {
        List<Point> pointsList = pointService.getAllByStreet(streetItem);
        List<String> pointNames = new ArrayList<String>();
        for (Point pointItem : pointsList) {
            pointNames.add(pointItem.getName());
        }
        pointsMap.put(streetItem.getName(), pointNames);
    }
    // pointsMap.put("", Arrays.asList("12", "22", "34"));
    // pointsMap.put("", Arrays.asList("2", "4", "45", "13", "78"));
    // pointsMap.put("", Arrays.asList("10", "12", "22", "4", "6"));

    IModel<List<? extends String>> makeChoices = new AbstractReadOnlyModel<List<? extends String>>() {
        @Override
        public List<String> getObject() {
            return new ArrayList<String>(pointsMap.keySet());
        }

    };

    IModel<List<? extends String>> modelChoices = new AbstractReadOnlyModel<List<? extends String>>() {
        @Override
        public List<String> getObject() {
            List<String> points = pointsMap.get(selectedStreetName);
            if (points == null) {
                points = Collections.emptyList();
            }
            return points;
        }

    };

    Form<Void> form = new Form<Void>("form");
    add(form);

    final DropDownChoice<String> streets = new DropDownChoice<String>("streets",
            new PropertyModel<String>(this, "selectedStreetName"), makeChoices);

    final DropDownChoice<String> points = new DropDownChoice<String>("points", new Model<String>(),
            modelChoices);
    points.setOutputMarkupId(true);

    form.add(streets);
    form.add(points);

    final FeedbackPanel feedback = new FeedbackPanel("feedback");
    feedback.setOutputMarkupId(true);
    add(feedback);

    form.add(new AjaxButton("go") {
        @Override
        protected void onAfterSubmit(AjaxRequestTarget target, Form<?> form) {
            super.onAfterSubmit(target, form);
            info(" : " + streets.getModelObject() + " "
                    + points.getModelObject());
            target.add(feedback);
        }
    });

    streets.add(new AjaxFormComponentUpdatingBehavior("change") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(points);
        }
    });

    Form<Void> ajaxForm = new Form<Void>("ajaxForm");
    add(ajaxForm);

    final AutoCompleteTextField<String> field = new AutoCompleteTextField<String>("ac", new Model<String>("")) {
        @Override
        protected Iterator<String> getChoices(String input) {
            if (Strings.isEmpty(input)) {
                List<String> emptyList = Collections.emptyList();
                return emptyList.iterator();
            }

            List<String> choices = new ArrayList<String>(10);

            List<Street> streetsList = streetService.getAllByCity(city);

            for (final Street streetItem : streetsList) {
                final String streetName = streetItem.getName();

                if (streetName.toUpperCase().startsWith(input.toUpperCase())) {
                    choices.add(streetName);
                    if (choices.size() == 10) {
                        break;
                    }
                }
            }

            return choices.iterator();
        }
    };

    ajaxForm.add(field);

    final Label label = new Label("selectedValue", field.getDefaultModel());
    label.setOutputMarkupId(true);
    ajaxForm.add(label);

    field.add(new AjaxFormSubmitBehavior(ajaxForm, "onchange") {
        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            target.add(label);
            List<Street> streetList = streetService.getAllByCityAndName(city,
                    label.getDefaultModelObjectAsString());
            if (streetList.size() == 1) {
                setSelectedStreet(streetList.get(0));
            }
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
        }
    });
}

From source file:ca.travelagency.BasePage.java

License:Apache License

@Override
public void onEvent(IEvent<?> event) {
    super.onEvent(event);

    Object payload = event.getPayload();
    if (payload instanceof AjaxRequestTarget) {
        AjaxRequestTarget ajaxRequestTarget = (AjaxRequestTarget) payload;
        ajaxRequestTarget.add(feedbackPanel);
    }//from  ww  w  .  ja va2s.c  om
}

From source file:ca.travelagency.components.behaviors.AjaxOnBlurBehavior.java

License:Apache License

@Override
protected void onUpdate(AjaxRequestTarget target) {
    target.add(getComponent());
}

From source file:ca.travelagency.components.behaviors.AjaxOnBlurBehavior.java

License:Apache License

@Override
protected void onError(AjaxRequestTarget target, RuntimeException e) {
    target.add(getComponent());
}

From source file:ca.travelagency.components.formdetail.DeleteLink.java

License:Apache License

@Override
public void onClick(AjaxRequestTarget target) {
    ajaxLinkCallback.onClick(target);//from   w  w w .j a  v a 2s .  c o  m
    target.appendJavaScript(JSUtils.INITIALIZE);
    target.add(component);
}

From source file:ca.travelagency.components.formdetail.DetailsPanel.java

License:Apache License

protected void updateDisplay(AjaxRequestTarget target) {
    details.detachModels();
    target.add(webMarkupContainer);
}

From source file:ca.travelagency.components.formdetail.SaveButtonDetail.java

License:Apache License

@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
    @SuppressWarnings("unchecked")
    Form<T> typedForm = (Form<T>) form;
    target.add(typedForm);
    target.appendJavaScript(JSUtils.INITIALIZE);
    target.appendJavaScript(/*ww  w .  j a v  a 2  s  . c o m*/
            DaoEntityModelFactory.isPersisted(typedForm.getModelObject()) ? JSUtils.HIDE_ROW_CONTROLS
                    : JSUtils.SHOW_ROW_CONTROLS);
}