List of usage examples for org.apache.wicket.validation.validator EmailAddressValidator getInstance
public static EmailAddressValidator getInstance()
EmailAddressValidator
. From source file:au.org.theark.study.web.component.manageuser.form.DetailForm.java
License:Open Source License
@Override protected void attachValidators() { lastNameTxtField.add(StringValidator.lengthBetween(1, 50)) .setLabel(new StringResourceModel("lastName", this, null)); lastNameTxtField.setRequired(true);/* w w w . j a va 2 s .com*/ userNameTxtField.add(StringValidator.lengthBetween(1, 50)) .setLabel(new StringResourceModel("userName", this, null)); userNameTxtField.add(EmailAddressValidator.getInstance()) .setLabel(new StringResourceModel("userName.incorrectPattern", this, null)); userNameTxtField.setRequired(true).setLabel(new StringResourceModel("userName", this, null)); firstNameTxtField.setRequired(true).setLabel(new StringResourceModel("firstName", this, null)); firstNameTxtField.add(StringValidator.lengthBetween(1, 50)) .setLabel(new StringResourceModel("firstName", this, null)); emailTxtField.add(StringValidator.lengthBetween(1, 50)) .setLabel(new StringResourceModel("email", this, null)); emailTxtField.add(EmailAddressValidator.getInstance()) .setLabel(new StringResourceModel("email.incorrectpattern", this, null)); emailTxtField.setRequired(true).setLabel(new StringResourceModel("email", this, null)); userPasswordField.setRequired(isNew()); confirmPasswordField.setRequired(isNew()); // Set the confirm password with a password pattern userPasswordField.setLabel(Model.of("Password")); userPasswordField.add(new PatternValidator(Constants.PASSWORD_PATTERN)); confirmPasswordField.setLabel(Model.of("Confirm Password")); }
From source file:au.org.theark.study.web.component.mydetails.form.MyDetailsForm.java
License:Open Source License
@SuppressWarnings({ "unchecked" }) public void initialiseForm() { //ArkUserVO arkUserVOFromBackend = new ArkUserVO(); try {//from www. j a v a2 s . co m ArkUserVO arkUserVOFromBackend = iUserService.lookupArkUser(getModelObject().getUserName(), getModelObject().getStudy()); Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); if (sessionStudyId != null) { arkUserVOFromBackend.setStudy(iArkCommonService.getStudy(sessionStudyId)); } else { arkUserVOFromBackend.setStudy(getModelObject().getStudy()); } //Study will selected with model object and that will be the page list view accordingly. listViewPanel.setOutputMarkupId(true); iModel = new LoadableDetachableModel() { private static final long serialVersionUID = 1L; @Override protected Object load() { return getModelObject().getArkRolePolicyTemplatesList(); } }; initStudyDdc(arkUserVOFromBackend); List<UserConfig> arkUserConfigs = iArkCommonService .getUserConfigs(arkUserVOFromBackend.getArkUserEntity()); arkUserVOFromBackend.setArkUserConfigs(arkUserConfigs); getModelObject().setArkUserConfigs(arkUserConfigs); } catch (ArkSystemException e) { log.error(e.getMessage()); } emailTxtField.setOutputMarkupId(true); saveButton = new AjaxButton(Constants.SAVE) { private static final long serialVersionUID = -8737230044711628981L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { onSave(target); } public void onError(AjaxRequestTarget target, Form<?> form) { processFeedback(target, feedbackPanel); } }; closeButton = new AjaxButton(Constants.CLOSE) { private static final long serialVersionUID = 5457464178392550628L; public void onSubmit(AjaxRequestTarget target, Form<?> form) { modalWindow.close(target); } public void onError(AjaxRequestTarget target, Form<?> form) { processFeedback(target, feedbackPanel); } }; closeButton.setDefaultFormProcessing(false); emailTxtField.add(EmailAddressValidator.getInstance()); boolean loggedInViaAAF = ((String) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.SHIB_SESSION_ID) != null); groupPasswordContainer.setVisible(!loggedInViaAAF); shibbolethSessionDetails .add(new AttributeModifier("src", ArkShibbolethServiceProviderContextSource.handlerUrl + ArkShibbolethServiceProviderContextSource.session)); shibbolethSession.add(new AttributeModifier("class", "paddedDetailPanel")); shibbolethSession.setVisible(loggedInViaAAF); shibbolethSession.add(shibbolethSessionDetails); userConfigListEditor = new AbstractListEditor<UserConfig>("arkUserConfigs") { @Override protected void onPopulateItem(au.org.theark.core.web.component.listeditor.ListItem<UserConfig> item) { item.add(new Label("configField.description", item.getModelObject().getConfigField().getDescription())); PropertyModel<String> propModel = new PropertyModel<String>(item.getModel(), "value"); TextField<String> valueTxtFld = new TextField<String>("value", propModel); item.add(valueTxtFld); item.add(new AttributeModifier("class", new AbstractReadOnlyModel() { private static final long serialVersionUID = -8887455455175404701L; @Override public String getObject() { return (item.getIndex() % 2 == 1) ? "even" : "odd"; } })); } }; attachValidators(); addComponents(); }
From source file:au.org.theark.study.web.component.mydetails.form.MyDetailsForm.java
License:Open Source License
private void attachValidators() { userNameTxtField.add(EmailAddressValidator.getInstance()) .setLabel(new StringResourceModel("userName.incorrect.format", this, null)); userNameTxtField.setRequired(true).setLabel(new StringResourceModel("userName", this, null)); userNameTxtField.add(StringValidator.lengthBetween(3, 50)) .setLabel(new StringResourceModel("userName", this, null)); firstNameTxtField.setRequired(true).setLabel(new StringResourceModel("firstName", this, null)); firstNameTxtField.add(StringValidator.lengthBetween(3, 50)) .setLabel(new StringResourceModel("firstName", this, null)); emailTxtField.add(EmailAddressValidator.getInstance()) .setLabel(new StringResourceModel("email.incorrect.format", this, null)); emailTxtField.setRequired(true).setLabel(new StringResourceModel("email", this, null)); lastNameTxtField.add(StringValidator.lengthBetween(3, 50)) .setLabel(new StringResourceModel("lastNameLength", this, null)); lastNameTxtField.setRequired(true).setLabel(new StringResourceModel("lastName", this, null)); userPasswordField.setRequired(false); confirmPasswordField.setRequired(false); userPasswordField.setLabel(Model.of("Password")); userPasswordField.add(new PatternValidator(Constants.PASSWORD_PATTERN)); confirmPasswordField.setLabel(Model.of("Confirm Password")); }
From source file:au.org.theark.study.web.component.subject.form.DetailForm.java
License:Open Source License
@Override protected void attachValidators() { subjectUIDTxtFld.setRequired(true).setLabel(new StringResourceModel("subject.uid.required", this, null)); dateOfBirthTxtFld.setLabel(/*from w w w .ja va 2 s . c o m*/ new StringResourceModel("linkSubjectStudy.person.dateOfBirth.DateValidator.maximum", this, null)); subjectStatusDdc.setRequired(true).setLabel(new StringResourceModel("subject.status.required", this, null)); consentDateTxtFld.setLabel(new StringResourceModel("consentDate", this, null)); consentDateTxtFld.add(DateValidator.maximum(new Date())).setLabel( new StringResourceModel("linkSubjectStudy.consentDate.DateValidator.maximum", this, null)); dateLastKnownAliveTxtFld.add(DateValidator.maximum(new Date())).setLabel(new StringResourceModel( "linkSubjectStudy.person.dateLastKnownAlive.DateValidator.maximum", this, null)); preferredEmailTxtFld.add(EmailAddressValidator.getInstance()); otherEmailTxtFld.add(EmailAddressValidator.getInstance()); consentStatusChoice.setRequired(true) .setLabel(new StringResourceModel("consentStatus.required", this, null)); //Add new validators on 2016-05-19(Ark-1603). firstNameTxtFld .add(StringValidator.maximumLength(au.org.theark.core.Constants.GENERAL_FIELD_NAME_MAX_LENGTH_50)); middleNameTxtFld .add(StringValidator.maximumLength(au.org.theark.core.Constants.GENERAL_FIELD_NAME_MAX_LENGTH_50)); lastNameTxtFld .add(StringValidator.maximumLength(au.org.theark.core.Constants.GENERAL_FIELD_NAME_MAX_LENGTH_50)); previousLastNameTxtFld .add(StringValidator.maximumLength(au.org.theark.core.Constants.GENERAL_FIELD_NAME_MAX_LENGTH_50)); preferredNameTxtFld .add(StringValidator.maximumLength(au.org.theark.core.Constants.GENERAL_FIELD_NAME_MAX_LENGTH_50)); causeOfDeathTxtFld.add(StringValidator .maximumLength(au.org.theark.core.Constants.GENERAL_FIELD_DESCRIPTIVE_MAX_LENGTH_255)); commentTxtAreaFld.add( StringValidator.maximumLength(au.org.theark.core.Constants.GENERAL_FIELD_COMMENTS_MAX_LENGTH_500)); heardAboutStudyTxtFld.add( StringValidator.maximumLength(au.org.theark.core.Constants.GENERAL_FIELD_COMMENTS_MAX_LENGTH_500)); preferredEmailTxtFld .add(StringValidator.maximumLength(au.org.theark.core.Constants.GENERAL_FIELD_NAME_MAX_LENGTH_50)); otherEmailTxtFld .add(StringValidator.maximumLength(au.org.theark.core.Constants.GENERAL_FIELD_NAME_MAX_LENGTH_50)); }
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);//w w w . j a va 2 s . c om 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.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);/*from w w w. j a v a 2 s.c o 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:ca.travelagency.config.CompanyPage.java
License:Apache License
private Form<Company> companyForm(IModel<Company> model) { Form<Company> form = new Form<Company>(COMPANY_FORM, model); form.setOutputMarkupId(true);//from ww w .jav a 2 s . co m form.add(new ComponentFeedbackPanel(FEEDBACK, form)); form.add(new RequiredTextField<String>(DaoEntity.PROPERTY_NAME).setLabel(new ResourceModel("company.name")) .add(StringFieldHelper.maxLenFieldValidator()).add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new RequiredTextField<String>(Company.Properties.address.name()) .setLabel(new ResourceModel("company.address")).add(StringFieldHelper.maxLenFieldValidator()) .add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new CityField(Company.Properties.city.name()).setLabel(new ResourceModel("company.city")) .add(StringFieldHelper.maxLenFieldValidator()).setRequired(true) .add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new ProvinceField(Company.Properties.province.name()) .setLabel(new ResourceModel("company.province")).setRequired(true) .add(StringFieldHelper.maxLenFieldValidator()).add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new RequiredTextField<String>(Company.Properties.postalCode.name()) .setLabel(new ResourceModel("company.postalCode")).add(StringFieldHelper.maxLenFieldValidator()) .add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new CountryField(Company.Properties.country.name()).setLabel(new ResourceModel("company.country")) .setRequired(true).add(StringFieldHelper.maxLenFieldValidator()) .add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new RequiredTextField<String>(Company.Properties.email.name()) .setLabel(new ResourceModel("company.email")).add(StringFieldHelper.maxLenFieldValidator()) .add(EmailAddressValidator.getInstance()).add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new RequiredTextField<String>(Company.Properties.phoneNumber.name()) .setLabel(new ResourceModel("company.phone")).add(StringFieldHelper.maxLenFieldValidator()) .add(new PhoneNumberValidator(), new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new RequiredTextField<String>(Company.Properties.faxNumber.name()) .setLabel(new ResourceModel("company.fax")).add(StringFieldHelper.maxLenFieldValidator()) .add(new PhoneNumberValidator(), new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new RequiredTextField<String>(Company.Properties.taxNumber.name()) .setLabel(new ResourceModel("company.HSTNumber")).add(StringFieldHelper.maxLenFieldValidator()) .add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new RequiredTextField<String>(Company.Properties.ticoNumber.name()) .setLabel(new ResourceModel("company.TICONumber")).add(StringFieldHelper.maxLenFieldValidator()) .add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new SavePanel<Company>(SAVE_BUTTON, form)); form.add(new ResetPanel<Company>(RESET_BUTTON, form)); return form; }
From source file:ca.travelagency.customer.CustomerPage.java
License:Apache License
public CustomerPage(Customer customer) { final Form<Customer> form = new Form<Customer>(FORM, DaoEntityModelFactory.make(customer, Customer.class)); form.setOutputMarkupId(true);//ww w . j ava2 s. c o m add(form); initialize(form); form.add(new ComponentFeedbackPanel(FEEDBACK, form)); form.add(new DropDownChoice<CustomerStatus>(Customer.Properties.status.name(), Arrays.asList(CustomerStatus.values())).setRequired(true) .setLabel(new ResourceModel("customer.status")).setEnabled(hasRole(Role.ADMIN)) .add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new SalutationField(Customer.Properties.salutation.name()) .setLabel(new ResourceModel("customer.salutation")).add(StringFieldHelper.maxLenFieldValidator()) .add(new FieldDecorator(), new AjaxOnBlurBehavior())); LastNameField lastNameField = new LastNameField(Customer.Properties.lastName.name()); form.add(lastNameField.setLabel(new ResourceModel("customer.lastName")).setRequired(true) .add(StringFieldHelper.maxLenFieldValidator()).add(new FieldDecorator(), new AjaxOnBlurBehavior())); FirstNameField firstNameField = new FirstNameField(Customer.Properties.firstName.name()); form.add(firstNameField.setLabel(new ResourceModel("customer.firstName")).setRequired(true) .add(StringFieldHelper.maxLenFieldValidator()).add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new CompanyNameField(Customer.Properties.companyName.name()) .setLabel(new ResourceModel("customer.companyName")).add(StringFieldHelper.maxLenFieldValidator()) .add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new TextField<String>(Customer.Properties.address.name()) .setLabel(new ResourceModel("customer.address")).add(StringFieldHelper.maxLenFieldValidator()) .add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new CityField(Customer.Properties.city.name()).setLabel(new ResourceModel("customer.city")) .add(StringFieldHelper.maxLenFieldValidator()).add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new ProvinceField(Customer.Properties.province.name()) .setLabel(new ResourceModel("customer.province")).add(StringFieldHelper.maxLenFieldValidator()) .add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new TextField<String>(Customer.Properties.postalCode.name()) .setLabel(new ResourceModel("customer.postalCode")).add(StringFieldHelper.maxLenFieldValidator()) .add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new CountryField(Customer.Properties.country.name()) .setLabel(new ResourceModel("customer.country")).add(StringFieldHelper.maxLenFieldValidator()) .add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new TextField<String>(Customer.Properties.email.name()) .setLabel(new ResourceModel("customer.email")).add(StringFieldHelper.maxLenFieldValidator()) .add(EmailAddressValidator.getInstance()).add(new FieldDecorator(), new AjaxOnBlurBehavior())); RequiredTextField<String> primaryPhoneNumber = new RequiredTextField<String>( Customer.Properties.primaryPhone.name()); form.add(primaryPhoneNumber.setLabel(new ResourceModel("customer.primaryPhone")) .add(StringFieldHelper.maxLenFieldValidator()) .add(new PhoneNumberValidator(), new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new TextField<String>(Customer.Properties.secondaryPhone.name()) .setLabel(new ResourceModel("customer.secondaryPhone")) .add(StringFieldHelper.maxLenFieldValidator()) .add(new PhoneNumberValidator(), new FieldDecorator(), new AjaxOnBlurBehavior())); DateField dateOfBirthField = new BirthDateField(Customer.Properties.dateOfBirth.name()); form.add(dateOfBirthField.setLabel(new ResourceModel("customer.dateOfBirth")).add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new TextArea<String>(Customer.Properties.notes.name()) .setLabel(new ResourceModel("customer.notes")).add(StringFieldHelper.maxLenAreaValidator()) .add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new SystemUserField(Customer.Properties.systemUser.name()) .setLabel(new ResourceModel("customer.agent")).setVisible(hasRole(Role.ADMIN)) .add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new TravelDocumentField(Customer.Properties.travelDocumentType.name()) .setLabel(new ResourceModel("customer.travelDocumentType")) .add(StringFieldHelper.maxLenFieldValidator()).add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new TextField<String>(Customer.Properties.travelDocumentNumber.name()) .setLabel(new ResourceModel("customer.travelDocumentNumber")) .add(StringFieldHelper.maxLenFieldValidator()).add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new CustomerDuplicateValidator(lastNameField, firstNameField, primaryPhoneNumber, dateOfBirthField)); form.add(new SavePanel<Customer>(SAVE_BUTTON, form) { private static final long serialVersionUID = 1L; @Override public void preSubmit(AjaxRequestTarget target, Customer daoEntity, boolean newDaoEntity) { if (newDaoEntity && !hasRole(Role.ADMIN)) { daoEntity.setSystemUser(getSignedInSystemUser()); } } @Override public void postSubmit(AjaxRequestTarget target, Customer daoEntity, boolean newDaoEntity) { if (newDaoEntity || hasRole(Role.ADMIN)) { setResponsePage(new CustomerPage(daoEntity)); } } }); form.add(new ResetPanel<Customer>(RESET_BUTTON, form)); form.add(new Link<String>(CREATE_INVOICE_BUTTON) { private static final long serialVersionUID = 1L; @Override public void onClick() { setResponsePage(new InvoicePage(form.getModelObject())); } }.setVisible(form.getModelObject().isActive() && isVisible(form.getModelObject()))); add(createInvoicePanel(form)); }
From source file:ca.travelagency.identity.SystemUserPage.java
License:Apache License
private Form<SystemUser> makeSystemUserForm(SystemUser systemUser) { final Form<SystemUser> form = new Form<SystemUser>(FORM, DaoEntityModelFactory.make(systemUser, SystemUser.class)); form.setOutputMarkupId(true);//from w ww. ja v a 2s .com form.add(new ComponentFeedbackPanel(FEEDBACK, form)); RequiredTextField<String> name = new RequiredTextField<String>(DaoEntity.PROPERTY_NAME); name.setLabel(new ResourceModel("systemUser.name")).add(StringFieldHelper.maxLenFieldValidator()) .add(new FieldDecorator(), new AjaxOnBlurBehavior(), new DuplicateValidator<SystemUser>(form)); form.add(name); form.add(new TextField<String>(SystemUser.Properties.lastName.name()) .setLabel(new ResourceModel("systemUser.lastName")).add(StringFieldHelper.maxLenFieldValidator()) .add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new TextField<String>(SystemUser.Properties.firstName.name()) .setLabel(new ResourceModel("systemUser.firstName")).add(StringFieldHelper.maxLenFieldValidator()) .add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new TextField<String>(SystemUser.Properties.email.name()) .setLabel(new ResourceModel("systemUser.email")).add(StringFieldHelper.maxLenFieldValidator()) .add(EmailAddressValidator.getInstance()).add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new TextField<String>(SystemUser.Properties.primaryPhone.name()) .setLabel(new ResourceModel("systemUser.primaryPhone")) .add(StringFieldHelper.maxLenFieldValidator()) .add(new PhoneNumberValidator(), new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new TextField<String>(SystemUser.Properties.secondaryPhone.name()) .setLabel(new ResourceModel("systemUser.secondaryPhone")) .add(StringFieldHelper.maxLenFieldValidator()) .add(new PhoneNumberValidator(), new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new CheckBox(SystemUser.Properties.active.name()).setLabel(new ResourceModel("systemUser.active")) .setVisible(hasRole(Role.ADMIN)).add(new FieldDecorator(), new AjaxOnBlurBehavior())); form.add(new NumberTextField<Double>(SystemUser.Properties.commissionRate.name()).setMinimum(0.00) .setMaximum(999.99).setLabel(new ResourceModel("systemUser.commissionRate")) .setVisible(hasRole(Role.ADMIN)).add(new FieldDecorator(), new AjaxOnBlurBehavior())); addPasswordFields(form); form.add(new SavePanel<SystemUser>(SAVE_BUTTON, form) { private static final long serialVersionUID = 1L; @Override public void preSubmit(AjaxRequestTarget target, SystemUser daoEntity, boolean newDaoEntity) { if (!newDaoEntity) { return; } daoEntity.addSystemUserRole(SystemUserRole.make(Role.AGENT)); } @Override public void postSubmit(AjaxRequestTarget target, SystemUser daoEntity, boolean newDaoEntity) { if (!newDaoEntity) { return; } setResponsePage(new SystemUserPage(daoEntity)); } }); form.add(new ResetPanel<SystemUser>(RESET_BUTTON, form)); return form; }
From source file:com.alfredmuponda.lostandfound.pages.LostReportForm.java
public LostReportForm() { itemTypes = Arrays.asList("Wallet", "National ID", "Drivers Licence", "Passport"); lf_items = new ArrayList(); contactInfo = new ContactInformation(); item = new Item(); Form form = new Form("form"); add(new HeaderPanel("headerpanel")); add(form);//from w w w. ja v a 2s .co m firstNameField = new TextField("firstname", new PropertyModel(contactInfo, "firstName")); surnameField = new TextField("surname", new PropertyModel(contactInfo, "surname")); addressField = new TextField("address", new PropertyModel(contactInfo, "address")); phoneNumberField = new TextField("phonenumber", new PropertyModel(contactInfo, "phoneNumber")); emailAddressField = new EmailTextField("emailaddress", new PropertyModel(contactInfo, "emailAddress")); dateField = new TextField("date", new PropertyModel(item, "dateLorF")); itemTypeField = new DropDownChoice("itemtype", new PropertyModel(item, "itemType"), itemTypes); itemIDField = new TextField("itemid", new PropertyModel(item, "itemID")); locationField = new TextArea("location", new PropertyModel(item, "location")); descriptionField = new TextArea("description", new PropertyModel(item, "description")); //Add validators for user input firstNameField.setRequired(true); surnameField.setRequired(true); addressField.setRequired(true); phoneNumberField.setRequired(true).add(new PhoneNumberValidator()); dateField.setRequired(true); itemTypeField.setRequired(true); itemIDField.add(new ItemNumberValidator(itemTypeField)); locationField.setRequired(true); descriptionField.setRequired(true); emailAddressField.add(EmailAddressValidator.getInstance()); form.add(new FeedbackPanel("feedback")); form.add(firstNameField); form.add(surnameField); form.add(addressField); form.add(phoneNumberField); form.add(emailAddressField); form.add(dateField); form.add(itemTypeField); form.add(itemIDField); form.add(locationField); form.add(descriptionField); form.add(new Button("submit") { @Override public void onSubmit() { getInfoInForm(); //JDBC persistence /* uuid = UUID.randomUUID().toString(); db = new ReadWriteDatabase(contactInfo, lf_items); db.addItemData(uuid); lf_items.clear(); */ //HIBERNATE persistance* persist(); lf_items.clear(); clear(); } }); form.add(new Button("addItem") { @Override public void onSubmit() { getInfoInForm(); check(); partialClear(); } }); form.add(new Link("clear") { @Override public void onClick() { clear(); } }); form.add(new Link("cancel") { @Override public void onClick() { setResponsePage(HomePage.class); } }); form.add(new Link("policereport") { @Override public void onClick() { PoliceReport report = new PoliceReport(); report.generatePoliceReport(uuid); setResponsePage(HomePage.class); } }); }