Example usage for org.apache.wicket.markup.html.form SubmitLink SubmitLink

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

Introduction

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

Prototype

public SubmitLink(String id) 

Source Link

Document

With this constructor the SubmitLink must be inside a Form.

Usage

From source file:au.org.emii.geoserver.extensions.filters.LayerFilterForm.java

License:Open Source License

private SubmitLink saveLink() {
    return new SubmitLink("save") {
        @Override/*  w  w w . java  2 s .  c  o  m*/
        public void onSubmit() {
            try {
                FilterConfiguration data = getModel().getObject();
                FilterConfigurationFile configurationFile = new FilterConfigurationFile(
                        data.getDataDirectory());
                configurationFile.write(data.getFilters());
            } catch (TemplateException te) {
                throw new RuntimeException(te);
            } catch (IOException ioe) {
                throw new RuntimeException(ioe);
            }
        }
    };
}

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);//from   w  w  w .  j  av a2s.  c  o  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);/*  ww w .jav  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.grodno.ss.rentacar.webapp.page.order.CheckoutPage.java

@Override
protected void onInitialize() {
    super.onInitialize();
    final NotificationPanel feedback = new NotificationPanel("feedbackpanel");

    SimpleDateFormat dt = new SimpleDateFormat("dd.MM.yyy HH:mm");
    add(new Label("duration",
            bookingService.convertDurationToString(filter.getDateFrom(), filter.getDateTo())));
    add(new Label("dateFrom", dt.format(filter.getDateFrom())));
    add(new Label("locationFrom", filter.getLocationFrom().getName()));
    add(new Label("dateTo", dt.format(filter.getDateTo())));
    add(new Label("locationTo", filter.getLocationTo().getName()));
    add(new Link<Void>("link-change") {
        private static final long serialVersionUID = 1L;

        @Override//  w  w  w.j  ava  2  s .c o m
        public void onClick() {
            setResponsePage(new ReservationPage(filter));
        }
    });
    add(new Link<Void>("link-change-car") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            setResponsePage(new ChooseCarPage(filter));
        }
    });
    addImage(car);
    add(new Label("name", car.getName()));
    add(new Label("type", car.getType().getName()));
    add(new Label("pass", car.getType().getNumPassengers()));
    add(new Label("bags", car.getType().getNumBags()));
    add(new Label("doors", car.getType().getNumDoors()));
    add(new Label("trans", car.getType().getTransmissionType()));

    add(new Label("rental-duration",
            bookingService.convertDurationToString(filter.getDateFrom(), filter.getDateTo())));
    BigDecimal pricePerHour = car.getType().getPricePerHour();
    totalPrice = bookingService.getTotalPrice(filter.getDateFrom(), filter.getDateTo(), pricePerHour);
    BigDecimal pricePerDay = bookingService.getPricePerDay(pricePerHour);
    int percent = settingService.get().getDepositPayment();
    BigDecimal requiredDeposit = bookingService.getRequiredDeposit(totalPrice, percent);
    add(new Label("pricePerHour", pricePerHour.toString()));
    add(new Label("total", totalPrice.toString()));
    add(new Label("pricePerDay", pricePerDay.toString()));
    add(new Label("requiredDeposit", requiredDeposit.toString()));
    add(new Label("total1", totalPrice.toString()));
    add(new Label("percent", percent));
    add(getPriceIcon("iconPrice1"));
    add(getPriceIcon("iconPrice2"));
    add(getPriceIcon("iconPrice3"));
    add(getPriceIcon("iconPrice4"));
    add(getPriceIcon("iconPrice5"));

    // -----checkout form------------
    Form<UserProfile> form = new Form<UserProfile>("form-checkout",
            new CompoundPropertyModel<UserProfile>(userProfile));
    // form.add(new FeedbackPanel("feedbackpanel"));

    TextField<String> firstName = new TextField<String>("firstName",
            new PropertyModel<>(userProfile, "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",
            new PropertyModel<>(userProfile, "lastName"));
    lastName.setRequired(true);
    lastName.add(StringValidator.maximumLength(100));
    lastName.add(StringValidator.minimumLength(2));
    firstName.add(new PatternValidator("[A-Za-z]+"));
    form.add(lastName);

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

    DateTextFieldConfig config = new DateTextFieldConfig();
    config.withLanguage(AuthorizedSession.get().getLocale().getLanguage());
    config.withFormat("dd.MM.yyyy");
    DateTextField dateBirth = new DateTextField("date-birth", new PropertyModel<>(userProfile, "birthDay"),
            config);
    form.add(dateBirth);

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

    TextField<String> note = new TextField<String>("note", new PropertyModel<>(booking, "note"));
    note.add(StringValidator.maximumLength(500));
    form.add(note);

    TextField<String> address = new TextField<String>("address", new PropertyModel<>(userProfile, "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", new PropertyModel<>(userProfile, "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", new PropertyModel<>(userProfile, "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>("zip-code", new PropertyModel<>(userProfile, "zipCode"));
    zip.add(StringValidator.maximumLength(20));
    zip.add(StringValidator.minimumLength(2));
    zip.add(new PatternValidator("[0-9]+"));
    form.add(zip);

    BootstrapCheckBoxPicker chk0 = new BootstrapCheckBoxPicker("check-confirm", Model.of(Boolean.FALSE));
    form.add(chk0);

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

        @Override
        public void onSubmit() {
            if (chk0.getModelObject().equals(false)) {
                info("You must to agree rental terms");
            } else {
                if (userProfile.getId() == null) {
                    userCredential.setEmail("unregistered user");
                    userCredential.setPassword("pswd");
                    userCredential.setRole(UserRole.UNREGISTERED);
                    userService.register(userProfile, userCredential);
                } else {
                    userService.update(userProfile);
                }
                booking.setSumm(totalPrice);
                booking.setClient(userProfile);
                booking.setOrderStatus(OrderStatus.pending);
                bookingService.saveOrUpdate(booking);
                setResponsePage(new ConfirmPage());
            }
        }
    });

    form.add(feedback);
    add(form);

}

From source file:by.grodno.ss.rentacar.webapp.page.register.RegisterPanel.java

@Override
protected void onInitialize() {
    super.onInitialize();
    Form<UserCredentials> form = new Form<UserCredentials>("form-register",
            new CompoundPropertyModel<UserCredentials>(userCredentials));
    form.add(new FeedbackPanel("feedbackpanel"));

    TextField<String> email = new TextField<String>("email");
    email.setRequired(true);//w  ww . j a v  a 2 s.  co m
    email.add(StringValidator.maximumLength(100));
    email.add(StringValidator.minimumLength(3));
    email.add(EmailAddressValidator.getInstance());
    form.add(email);

    PasswordTextField password = new PasswordTextField("password");
    password.setRequired(true);
    password.add(StringValidator.maximumLength(100));
    password.add(StringValidator.minimumLength(6));
    password.add(new PatternValidator("[A-Za-z0-9_-]+"));
    form.add(password);

    TextField<String> firstName = new TextField<String>("firstName",
            new PropertyModel<>(userProfile, "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",
            new PropertyModel<>(userProfile, "lastName"));
    lastName.setRequired(true);
    lastName.add(StringValidator.maximumLength(100));
    lastName.add(StringValidator.minimumLength(2));
    firstName.add(new PatternValidator("[A-Za-z]+"));
    form.add(lastName);

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

    DateTextFieldConfig config = new DateTextFieldConfig();
    config.withLanguage(AuthorizedSession.get().getLocale().getLanguage());
    config.withFormat("dd.MM.yyyy");
    DateTextField dateBirth = new DateTextField("date-birth", new PropertyModel<>(userProfile, "birthDay"),
            config);
    form.add(dateBirth);

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

    TextField<String> address = new TextField<String>("address", new PropertyModel<>(userProfile, "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", new PropertyModel<>(userProfile, "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", new PropertyModel<>(userProfile, "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>("zip-code", new PropertyModel<>(userProfile, "zipCode"));
    zip.add(StringValidator.maximumLength(20));
    zip.add(StringValidator.minimumLength(2));
    zip.add(new PatternValidator("[0-9]+"));
    form.add(zip);

    BootstrapCheckBoxPicker chk0 = new BootstrapCheckBoxPicker("check-confirm", Model.of(Boolean.FALSE));
    form.add(chk0);

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

        @Override
        public void onSubmit() {
            if (chk0.getModelObject().equals(false)) {
                info("You must to agree rental terms");
            } else {
                userCredentials.setRole(UserRole.CLIENT);
                if (userProfile.getId() == null) {
                    userService.register(userProfile, userCredentials);
                } else {
                    userService.update(userProfile);
                    userService.update(userCredentials);
                }
                setResponsePage(new LoginPage());
            }
        }
    });
    add(form);

}

From source file:com.apachecon.memories.UploadForm.java

License:Apache License

public UploadForm(String id, List<String> contentTypes) {
    super(id);/*from   ww w.  j a  v  a  2  s .  c  om*/
    this.contentTypes = contentTypes;

    setMultiPart(true);
    setMaxSize(Bytes.megabytes(2));

    add(uploadField = new FileUploadField("uploadField"));
    uploadField.setRequired(true);
    add(new SubmitLink("submit"));
}

From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.HeaderConfigUI.java

License:Apache License

private void addComponents() {

    editForm = new Form<Object>("edit-form");

    add(editForm);//from   www. j  a va  2 s .  c om

    WebMarkupContainer tableContainer = new WebMarkupContainer("table-container", getDefaultModel());
    tableContainer.setOutputMarkupId(true);

    useHeaderCheckbox = new CheckBox("useHeader");
    tableContainer.add(useHeaderCheckbox);
    tableContainer.add(new CheckBox("sizeIncludesHeader"));

    useHandshakeCheckBox = getUseHandshakeCheckBox();
    tableContainer.add(useHandshakeCheckBox);

    handshakeMsgTextField = getHandshakeMsgTextField();
    tableContainer.add(handshakeMsgTextField);

    // Create the list editor
    recalcTagOffsets(getConfig().getTags());
    editor = new ListEditor<HeaderTagConfig>("tags",
            new PropertyModel<List<HeaderTagConfig>>(getDefaultModel(), "tags")) {
        @Override
        protected void onPopulateItem(EditorListItem<HeaderTagConfig> item) {

            item.setModel(new CompoundPropertyModel<HeaderTagConfig>(item.getModelObject()));

            HeaderDataType dataType = item.getModelObject().getDataType();

            // Offset is displayed only for information
            item.add(new Label("offset").setOutputMarkupId(true));
            item.add(getDataTypeDropdown());
            item.add(getValueTextField().setEnabled(dataType.isHasValue()).setVisible(dataType.isHasValue()));
            item.add(getSizeTextField().setEnabled(dataType.isArrayAllowed()));

            // Create the edit links to be used in the list editor
            item.add(getInsertLink());
            item.add(getDeleteLink());
            item.add(getMoveUpLink().setVisible(item.getIndex() > 0));
            item.add(getMoveDownLink().setVisible(item.getIndex() < getList().size() - 1));
        }
    };

    Label noItemsLabel = new Label("no-items-label", new StringResourceModel("noheaderitems", this, null)) {
        @Override
        public boolean isVisible() {
            return editor.getList().size() == 0;
        }
    };

    tableContainer.add(editor);

    tableContainer.add(noItemsLabel);

    tableContainer.add(new SubmitLink("add-row-link") {
        @Override
        public void onSubmit() {
            editor.addItem(new HeaderTagConfig(HeaderDataType.Dummy));
            // Recalculate the offsets
            recalcOffsets();
            // Adjust the visibility of the edit links
            rebuildLinks(editor);
        }
    }.setDefaultFormProcessing(false));

    editForm.add(tableContainer);

    editForm.add(new HeaderFormValidator());
}

From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.MessageConfigUI.java

License:Apache License

private void addComponents() {

    // Select the first message for initial display
    if (getConfig().messages.isEmpty()) {
        // No messages configured. Create a new message with id=1.
        getConfig().addMessageConfig(new MessageConfig(1));
    }/* w  w  w  .ja v a 2  s  .c om*/

    currentMessage = getConfig().getMessageList().get(0);
    currentMessage.calcOffsets(getConfig().getMessageIdType().getByteSize());
    currentMessageId = currentMessage.getMessageId();

    // *******************************************************************************************
    // *** Form for XML import
    final FileUploadField uploadField = new FileUploadField("upload-field", new ListModel<FileUpload>());

    Form<?> uploadForm = new Form<Object>("upload-form") {
        @Override
        protected void onSubmit() {
            try {
                FileUpload upload = uploadField.getFileUpload();
                if (upload != null) {
                    handleOnUpload(upload.getInputStream());
                } else {
                    warn(new StringResourceModel("warn.noFileToUpload", this, null).getString());
                }
            } catch (Exception e) {
                this.error(new StringResourceModel("import.error", this, null).getString() + " Exception: "
                        + e.toString());
            }
        }
    };
    uploadForm.add(uploadField);

    SubmitLink importLink = new SubmitLink("import-link");
    uploadForm.add(importLink);

    add(uploadForm);

    // *******************************************************************************************
    // *** The message configuration
    currentMessageModel = new PropertyModel<MessageConfig>(this, "currentMessage");
    editForm = new Form<MessageConfig>("edit-form",
            new CompoundPropertyModel<MessageConfig>(currentMessageModel)) {
        @Override
        protected void onError() {
            // Validation error - reset the message dropdown to the original value
            // Clear input causes the component to reload the model
            currentMessageIdDropdown.clearInput();
            super.onError();
        }
    };

    editForm.add(new MessageFormValidator());

    WebMarkupContainer tableContainer = new WebMarkupContainer("table-container");

    messageIdTypeDropDown = getMessageIdTypeDropdown();
    tableContainer.add(messageIdTypeDropDown);

    currentMessageIdDropdown = getCurrentMessageIdDropdown();

    tableContainer.add(currentMessageIdDropdown);
    Button buttonNew = new Button("new");
    buttonNew.add(new AjaxFormSubmitBehavior("onclick") {
        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            handleNew(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
            handleError(target);
        }
    });
    tableContainer.add(buttonNew);

    Button buttonCopy = new Button("copy");
    buttonCopy.add(new AjaxFormSubmitBehavior("onclick") {
        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            handleCopy(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
            handleError(target);
        }
    });
    tableContainer.add(buttonCopy);

    Button deleteButton = new Button("delete");
    deleteButton.add(new AjaxEventBehavior("onclick") {
        @Override
        protected void onEvent(AjaxRequestTarget target) {
            handleDelete(target);
        }
    });
    tableContainer.add(deleteButton);

    messageTypeDropdown = getMessageTypeDropdown();
    tableContainer.add(messageTypeDropdown);

    tableContainer.add(getQueueModeDropdown());

    tableContainer.add(new CheckBox("usePersistance").setOutputMarkupId(true));

    WebMarkupContainer listEditorContainer = new WebMarkupContainer("list-editor");

    messageIdTextField = getMessageIdTextField();
    listEditorContainer.add(messageIdTextField);

    messageAliasTextField = getMessageAliasTextField();
    listEditorContainer.add(messageAliasTextField);

    // Create the list editor
    editor = new ListEditor<TagConfig>("tags",
            new PropertyModel<List<TagConfig>>(currentMessageModel, "tags")) {
        @Override
        protected void onPopulateItem(EditorListItem<TagConfig> item) {

            item.setModel(new CompoundPropertyModel<TagConfig>(item.getModelObject()));

            BinaryDataType dataType = item.getModelObject().getDataType();
            boolean enable = dataType.isSpecial() ? false : true;

            // Offset is displayed only for information
            item.add(new Label("offset").setOutputMarkupId(true));

            if (enable) {
                item.add(getIdTextField());
            } else {
                // The static TextField has no validation. Validation would fail for special tags.
                item.add(getSpecialIdTextField().setEnabled(false));
            }

            item.add(getAliasTextField().setVisible(enable));

            item.add(getSizeTextField().setEnabled(dataType.isArrayAllowed()));

            item.add(getTagLengthTypeDropDown().setEnabled(dataType.supportsVariableLength()));

            item.add(getDataTypeDropdown());

            // Create the edit links to be used in the list editor
            item.add(getInsertLink());
            item.add(getDeleteLink());
            item.add(getMoveUpLink().setVisible(item.getIndex() > 0));
            item.add(getMoveDownLink().setVisible(item.getIndex() < getList().size() - 1));
        }
    };
    listEditorContainer.add(editor);

    Label noItemsLabel = new Label("no-items-label", new StringResourceModel("noitems", this, null)) {
        @Override
        public boolean isVisible() {
            return editor.getList().size() == 0;
        }
    };

    listEditorContainer.add(noItemsLabel);

    listEditorContainer.add(new EditorSubmitLink("add-row-link") {
        @Override
        public void onSubmit() {
            editor.addItem(new TagConfig());

            // Adjust the visibility of the edit links
            updateListEditor(editor);
        }
    });

    listEditorContainer.setOutputMarkupId(true);

    tableContainer.add(listEditorContainer);
    editForm.add(tableContainer);

    // XML export
    SubmitLink exportLink = new SubmitLink("export-link", editForm) {
        @Override
        public void onSubmit() {
            ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(getResourceStream(),
                    getFileName());
            handler.setContentDisposition(ContentDisposition.ATTACHMENT);
            handler.setCacheDuration(Duration.NONE);
            getRequestCycle().scheduleRequestHandlerAfterCurrent(handler);
        }

        private String getFileName() {
            return String.format("MsgConfig_%s.xml", currentMessageModel.getObject().getMessageId());
        }

        private IResourceStream getResourceStream() {
            String config = currentMessageModel.getObject().toXMLString();
            return new StringResourceStream(config, "text/xml");
        }
    };
    editForm.add(exportLink);

    uploadForm.add(editForm);
}

From source file:com.cubeia.backoffice.web.user.EditUser.java

License:Open Source License

/**
* Constructor that is invoked when page is invoked without a session.
* 
* @param parameters//www .ja  va  2s  . c  om
*            Page parameters
*/
public EditUser(PageParameters params) {
    if (!assertValidUserid(params)) {
        return;
    }

    final Long userId = params.get(PARAM_USER_ID).toLongObject();
    loadFormData(userId);

    if (getUser() == null || getUser().getStatus() == UserStatus.REMOVED) {
        log.debug("user is removed, id = " + userId);
        setInvalidUserResponsePage(userId);
        return;
    }

    add(createBlockActionLink(userId));

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

        @Override
        public void onClick() {
            userService.setUserStatus(userId, UserStatus.REMOVED);
            setInvalidUserResponsePage(userId);
        }
    });

    Form<?> userForm = new Form<Void>("userForm") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit() {
            userService.updateUser(user);
            info("User updated, id = " + user.getUserId());
            loadFormData(userId);
        }
    };

    CompoundPropertyModel<?> cpm = new CompoundPropertyModel<EditUser>(this);

    userForm.add(new Label(PARAM_USER_ID, cpm.bind("user.userId")));
    userForm.add(new Label("status", cpm.bind("user.status")));
    userForm.add(new TextField<Long>("operatorId", cpm.<Long>bind("user.operatorId")).setEnabled(false));
    userForm.add(new TextField<String>("externalUserId", cpm.<String>bind("user.externalUserId")));
    userForm.add(new TextField<String>("userName", cpm.<String>bind("user.userName")));
    userForm.add(new TextField<String>("firstName", cpm.<String>bind("user.userInformation.firstName")));
    userForm.add(new TextField<String>("lastName", cpm.<String>bind("user.userInformation.lastName")));
    userForm.add(new TextField<String>("email", cpm.<String>bind("user.userInformation.email"))
            .add(EmailAddressValidator.getInstance()));
    userForm.add(new TextField<String>("title", cpm.<String>bind("user.userInformation.title")));
    userForm.add(new TextField<String>("city", cpm.<String>bind("user.userInformation.city")));
    userForm.add(
            new TextField<String>("billingAddress", cpm.<String>bind("user.userInformation.billingAddress")));
    userForm.add(new TextField<String>("fax", cpm.<String>bind("user.userInformation.fax")));
    userForm.add(new TextField<String>("cellphone", cpm.<String>bind("user.userInformation.cellphone")));
    userForm.add(new DropDownChoice<String>("country", cpm.<String>bind("user.userInformation.country"),
            Arrays.asList(Locale.getISOCountries()), new IChoiceRenderer<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getDisplayValue(String isoCountry) {
                    return new Locale(Locale.ENGLISH.getLanguage(), (String) isoCountry)
                            .getDisplayCountry(Locale.ENGLISH);
                }

                @Override
                public String getIdValue(String isoCountry, int id) {
                    return "" + id;
                }
            }));

    userForm.add(new TextField<String>("zipcode", cpm.<String>bind("user.userInformation.zipcode")));
    userForm.add(new TextField<String>("state", cpm.<String>bind("user.userInformation.state")));
    userForm.add(new TextField<String>("phone", cpm.<String>bind("user.userInformation.phone")));
    userForm.add(new TextField<String>("workphone", cpm.<String>bind("user.userInformation.workphone")));
    userForm.add(new DropDownChoice<Gender>("gender", cpm.<Gender>bind("user.userInformation.gender"),
            Arrays.asList(Gender.values())));
    userForm.add(createAttributesListView());
    add(userForm);

    Form<?> addAttributeForm = new Form<Void>("addAttrForm") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit() {
            if (user.getAttributes() == null) {
                user.setAttributes(new HashMap<String, String>());
            }
            if (getNewAttributeKey() != null) {
                user.getAttributes().put("" + getNewAttributeKey(), "" + getNewAttributeValue());
            }
            setNewAttributeKey(null);
            setNewAttributeValue(null);
        }
    };
    addAttributeForm.add(new SubmitLink("addAttrLink").add(new Label("addAttrLabel", "Add attribute")));
    addAttributeForm.add(new TextField<String>("newAttrKey", cpm.<String>bind("newAttributeKey")));
    addAttributeForm.add(new TextField<String>("newAttrValue", cpm.<String>bind("newAttributeValue")));
    userForm.add(addAttributeForm);

    Form<?> pwdForm = new Form<Void>("changePasswordForm") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit() {
            userService.updatePassword(user.getUserId(), getPassword1());
            setPassword1(null);
            setPassword2(null);
        }
    };
    PasswordTextField pwd1 = new PasswordTextField("password1", cpm.<String>bind("password1"));
    PasswordTextField pwd2 = new PasswordTextField("password2", cpm.<String>bind("password2"));
    pwdForm.add(new EqualPasswordInputValidator(pwd1, pwd2));
    pwdForm.add(pwd1);
    pwdForm.add(pwd2);
    add(pwdForm);

    add(new FeedbackPanel("feedback"));
}

From source file:com.cubeia.games.poker.admin.wicket.pages.user.EditUser.java

License:Open Source License

/**
* Constructor that is invoked when page is invoked without a session.
* 
* @param parameters//from   ww w  .  j a  va  2s  .  c  om
*            Page parameters
*/
public EditUser(PageParameters parameters) {
    super(parameters);
    if (!assertValidUserid(parameters)) {
        return;
    }

    final Long userId = parameters.get(PARAM_USER_ID).toLongObject();
    loadFormData(userId);

    if (getUser() == null || getUser().getStatus() == UserStatus.REMOVED) {
        log.debug("user is removed, id = " + userId);
        setInvalidUserResponsePage(userId);
        return;
    }

    add(createBlockActionLink(userId));

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

        @Override
        public void onClick() {
            userService.setUserStatus(userId, UserStatus.REMOVED);
            setInvalidUserResponsePage(userId);
        }
    });

    Form<?> userForm = new Form<Void>("userForm") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit() {
            userService.updateUser(user);
            info("User updated, id = " + user.getUserId());
            loadFormData(userId);
        }
    };

    CompoundPropertyModel<?> cpm = new CompoundPropertyModel<EditUser>(this);

    userForm.add(new Label(PARAM_USER_ID, cpm.bind("user.userId")));
    userForm.add(new Label("status", cpm.bind("user.status")));
    userForm.add(new TextField<Long>("operatorId", cpm.<Long>bind("user.operatorId")).setEnabled(false));
    userForm.add(new TextField<String>("externalUserId", cpm.<String>bind("user.externalUserId")));
    userForm.add(new TextField<String>("userName", cpm.<String>bind("user.userName")));
    userForm.add(new TextField<String>("firstName", cpm.<String>bind("user.userInformation.firstName")));
    userForm.add(new TextField<String>("lastName", cpm.<String>bind("user.userInformation.lastName")));
    userForm.add(new TextField<String>("email", cpm.<String>bind("user.userInformation.email"))
            .add(EmailAddressValidator.getInstance()));
    userForm.add(new TextField<String>("title", cpm.<String>bind("user.userInformation.title")));
    userForm.add(new TextField<String>("city", cpm.<String>bind("user.userInformation.city")));
    userForm.add(
            new TextField<String>("billingAddress", cpm.<String>bind("user.userInformation.billingAddress")));
    userForm.add(new TextField<String>("fax", cpm.<String>bind("user.userInformation.fax")));
    userForm.add(new TextField<String>("cellphone", cpm.<String>bind("user.userInformation.cellphone")));
    userForm.add(new DropDownChoice<String>("country", cpm.<String>bind("user.userInformation.country"),
            Arrays.asList(Locale.getISOCountries()), new IChoiceRenderer<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getDisplayValue(String isoCountry) {
                    return new Locale(Locale.ENGLISH.getLanguage(), (String) isoCountry)
                            .getDisplayCountry(Locale.ENGLISH);
                }

                @Override
                public String getIdValue(String isoCountry, int id) {
                    return "" + id;
                }
            }));

    userForm.add(new TextField<String>("zipcode", cpm.<String>bind("user.userInformation.zipcode")));
    userForm.add(new TextField<String>("state", cpm.<String>bind("user.userInformation.state")));
    userForm.add(new TextField<String>("phone", cpm.<String>bind("user.userInformation.phone")));
    userForm.add(new TextField<String>("workphone", cpm.<String>bind("user.userInformation.workphone")));
    userForm.add(new DropDownChoice<Gender>("gender", cpm.<Gender>bind("user.userInformation.gender"),
            Arrays.asList(Gender.values())));
    userForm.add(createAttributesListView());
    add(userForm);

    Form<?> addAttributeForm = new Form<Void>("addAttrForm") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit() {
            if (user.getAttributes() == null) {
                user.setAttributes(new HashMap<String, String>());
            }
            if (getNewAttributeKey() != null) {
                user.getAttributes().put("" + getNewAttributeKey(), "" + getNewAttributeValue());
            }
            setNewAttributeKey(null);
            setNewAttributeValue(null);
        }
    };
    addAttributeForm.add(new SubmitLink("addAttrLink").add(new Label("addAttrLabel", "Add attribute")));
    addAttributeForm.add(new TextField<String>("newAttrKey", cpm.<String>bind("newAttributeKey")));
    addAttributeForm.add(new TextField<String>("newAttrValue", cpm.<String>bind("newAttributeValue")));
    userForm.add(addAttributeForm);

    Form<?> pwdForm = new Form<Void>("changePasswordForm") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit() {
            userService.updatePassword(user.getUserId(), getPassword1());
            setPassword1(null);
            setPassword2(null);
        }
    };
    PasswordTextField pwd1 = new PasswordTextField("password1", cpm.<String>bind("password1"));
    PasswordTextField pwd2 = new PasswordTextField("password2", cpm.<String>bind("password2"));
    pwdForm.add(new EqualPasswordInputValidator(pwd1, pwd2));
    pwdForm.add(pwd1);
    pwdForm.add(pwd2);
    add(pwdForm);

    add(new FeedbackPanel("feedback"));
}