List of usage examples for org.apache.wicket.validation.validator RangeValidator minimum
public static <T extends Comparable<? super T> & Serializable> RangeValidator<T> minimum(T minimum)
From source file:com.cubeia.games.poker.admin.wicket.pages.tournaments.configuration.TournamentConfigurationPanel.java
License:Open Source License
@SuppressWarnings({ "unchecked", "rawtypes" }) public TournamentConfigurationPanel(String id, Form<?> form, PropertyModel<TournamentConfiguration> propertyModel, boolean sitAndGo) { super(id, propertyModel); this.model = propertyModel; add(new RequiredTextField<String>("name", new PropertyModel(model, "name"))); add(new RequiredTextField<Integer>("seatsPerTable", new PropertyModel(model, "seatsPerTable"))); DropDownChoice<TimingProfile> timing = new DropDownChoice<TimingProfile>("timingType", model("timingType"), adminDAO.getTimingProfiles(), renderer("name")); timing.setRequired(true);/* w w w . j a va2 s. com*/ add(timing); TextField<Integer> minPlayers = new TextField<Integer>("minPlayers", new PropertyModel(model, "minPlayers")); minPlayers.add(RangeValidator.minimum(2)); add(minPlayers); TextField<Integer> maxPlayers = new TextField<Integer>("maxPlayers", new PropertyModel(model, "maxPlayers")); maxPlayers.add(RangeValidator.minimum(2)); add(maxPlayers); add(new RequiredTextField<BigDecimal>("buyIn", new PropertyModel(model, "buyIn"))); add(new RequiredTextField<BigDecimal>("fee", new PropertyModel(model, "fee"))); add(new RequiredTextField<BigDecimal>("guaranteedPrizePool", new PropertyModel(model, "guaranteedPrizePool"))); add(new CheckBox("payoutAsBonus", new PropertyModel(model, "payOutAsBonus"))); add(new RequiredTextField<BigDecimal>("startingChips", new PropertyModel(model, "startingChips"))); DropDownChoice<BetStrategyType> strategy = new DropDownChoice<BetStrategyType>("betStrategy", new PropertyModel(model, "betStrategy"), asList(BetStrategyType.values()), renderer("name")); strategy.setRequired(true); add(strategy); DropDownChoice<PokerVariant> variant = new DropDownChoice<PokerVariant>("variant", new PropertyModel(model, "variant"), asList(PokerVariant.values()), renderer("name")); variant.setRequired(true); add(variant); form.add(new TournamentPlayersValidator(minPlayers, maxPlayers)); final List<OperatorDTO> operators = networkClient.getOperators(); add(new ListMultipleChoice<Long>("operatorIds", model("operatorIds"), getOperatorIds(operators), new IChoiceRenderer<Long>() { @Override public Object getDisplayValue(Long id) { return getOperatorName(operators, id); } @Override public String getIdValue(Long object, int index) { return object.toString(); } })); TextField<String> userRule = new TextField<String>("userRuleExpression", new PropertyModel(model, "userRuleExpression")); add(userRule); DropDownChoice<String> currency = new DropDownChoice<String>("currency", model("currency"), networkClient.getCurrencies(), new ChoiceRenderer<String>()); currency.setRequired(true); add(currency); DropDownChoice<BlindsStructure> blindsStructure = new DropDownChoice<BlindsStructure>("blindsStructure", model("blindsStructure"), adminDAO.getBlindsStructures(), renderer("name")); blindsStructure.setRequired(true); add(blindsStructure); DropDownChoice<PayoutStructure> payoutStructure = new DropDownChoice<PayoutStructure>("payoutStructure", model("payoutStructure"), adminDAO.getPayoutStructures(), renderer("name")); payoutStructure.setRequired(true); add(payoutStructure); if (sitAndGo) { maxPlayers.setVisible(false); } TextArea<String> description = new TextArea<String>("description", new PropertyModel(model, "description")); description.add(StringValidator.maximumLength(1000)); add(description); }
From source file:com.tysanclan.site.projectewok.components.ActivateSubscriptionPanel.java
License:Open Source License
public ActivateSubscriptionPanel(String id, User user, IOnSubmitPageCreator onSubmitLink) { super(id);//from w ww . j av a 2s. c om this.onSubmitLink = onSubmitLink; if (user.getSubscription() != null) { setVisible(false); } final TextField<BigDecimal> amountField = new TextField<BigDecimal>("amount", new Model<BigDecimal>(TWO), BigDecimal.class); amountField.add(RangeValidator.minimum(TWO)); amountField.setRequired(true); final DropDownChoice<ExpensePeriod> expenseSelect = new DropDownChoice<ExpensePeriod>("regularity", new Model<ExpensePeriod>(ExpensePeriod.MONTHLY), Arrays.asList(ExpensePeriod.values()), new ExpensePeriodRenderer(false)); expenseSelect.setRequired(true); expenseSelect.setNullValid(false); Form<User> subscribeForm = new Form<User>("subscribeForm", ModelMaker.wrap(user)) { private static final long serialVersionUID = 1L; @SpringBean private FinanceService financeService; @Override protected void onSubmit() { super.onSubmit(); if (financeService.subscribe(getModelObject(), amountField.getModelObject(), expenseSelect.getModelObject())) { setResponsePage(ActivateSubscriptionPanel.this.onSubmitLink.createPage()); } else { error("Subscription failed. Most likely you already have one and submitted this form twice"); } } }; subscribeForm.add(amountField); subscribeForm.add(expenseSelect); add(subscribeForm); }
From source file:com.tysanclan.site.projectewok.pages.member.admin.SiteWideNotificationPage.java
License:Open Source License
public SiteWideNotificationPage(User user) { super("Site Wide Notification"); if (!getUser().equals(roleService.getSteward())) { throw new RestartResponseAtInterceptPageException(AccessDeniedPage.class); }//www . j a va2s. co m final TextField<String> messageField = new TextField<String>("message", new Model<String>("")); messageField.setRequired(true); final DropDownChoice<Category> categorySelect = new DropDownChoice<Category>("category", new Model<Category>(Category.INFO), Arrays.asList(Category.values())); categorySelect.setNullValid(false); categorySelect.setRequired(true); String[] durations = new String[DurationTypes.values().length]; int i = 0; for (DurationTypes t : DurationTypes.values()) { durations[i++] = t.getDescriptor(); } final DropDownChoice<String> durationTypeSelect = new DropDownChoice<String>("durationType", new Model<String>("minutes"), Arrays.asList(durations)); durationTypeSelect.setNullValid(false); durationTypeSelect.setRequired(true); final TextField<Integer> durationField = new TextField<Integer>("duration", new Model<Integer>(1), Integer.class); durationField.add(RangeValidator.minimum(1)); durationField.setRequired(true); Form<SiteWideNotification> notificationForm = new Form<SiteWideNotification>("notificationForm") { private static final long serialVersionUID = 1L; /** * @see org.apache.wicket.markup.html.form.Form#onSubmit() */ @Override protected void onSubmit() { String message = messageField.getModelObject(); Category category = categorySelect.getModelObject(); String durationType = durationTypeSelect.getModelObject(); Integer durationAmount = durationField.getModelObject(); Duration d = Duration.minutes(1); for (DurationTypes t : DurationTypes.values()) { if (t.getDescriptor().equals(durationType)) { d = t.getDuration(durationAmount); } } SiteWideNotification not = new SiteWideNotification(category, message, d); TysanApplication.get().notify(not); setResponsePage(new OverviewPage()); } }; notificationForm.add(messageField); notificationForm.add(categorySelect); notificationForm.add(durationTypeSelect); notificationForm.add(durationField); add(notificationForm); }
From source file:cz.zcu.kiv.eegdatabase.wui.ui.experiments.forms.ScenarioForm.java
License:Apache License
public ScenarioForm(String id, final ModalWindow window) { super(id, new CompoundPropertyModel<Scenario>(new Scenario())); add(new Label("addScenarioHeader", ResourceUtils.getModel("pageTitle.addScenario"))); final FeedbackPanel feedback = new FeedbackPanel("feedback"); feedback.setOutputMarkupId(true);/*from ww w.ja v a2s . c o m*/ add(feedback); setMultiPart(true); Person owner = getModel().getObject().getPerson(); if (owner == null) owner = EEGDataBaseSession.get().getLoggedUser(); getModel().getObject().setPerson(owner); List<ResearchGroup> choices = researchGroupFacade.getResearchGroupsWhereAbleToWriteInto(owner); if (choices == null || choices.isEmpty()) choices = Arrays.asList(getModel().getObject().getResearchGroup()); DropDownChoice<ResearchGroup> groups = new DropDownChoice<ResearchGroup>("researchGroup", choices, new ChoiceRenderer<ResearchGroup>("title")); groups.setRequired(true); TextField<String> title = new TextField<String>("title"); title.setLabel(ResourceUtils.getModel("label.scenarioTitle")); title.setRequired(true); // title.add(new TitleExistsValidator()); TextField<Integer> length = new TextField<Integer>("scenarioLength", Integer.class); length.setRequired(true); length.add(RangeValidator.minimum(0)); TextArea<String> description = new TextArea<String>("description"); description.setRequired(true); description.setLabel(ResourceUtils.getModel("label.scenarioDescription")); final WebMarkupContainer fileContainer = new WebMarkupContainer("contailer"); fileContainer.setVisibilityAllowed(false); fileContainer.setOutputMarkupPlaceholderTag(true); /* * TODO file field for xml was not visible in old portal. I dont know why. So I hided it but its implemented and not tested. */ // hidded line in old portal final DropDownChoice<ScenarioSchemas> schemaList = new DropDownChoice<ScenarioSchemas>("schemaList", new Model<ScenarioSchemas>(), scenariosFacade.getListOfScenarioSchemas(), new ChoiceRenderer<ScenarioSchemas>("schemaName", "schemaId")); schemaList.setOutputMarkupPlaceholderTag(true); schemaList.setRequired(true); schemaList.setLabel(ResourceUtils.getModel("label.scenarioSchema")); schemaList.setVisibilityAllowed(false); final FileUploadField file = new FileUploadField("file", new ListModel<FileUpload>()); file.setOutputMarkupId(true); file.setLabel(ResourceUtils.getModel("description.fileType.dataFile")); file.setOutputMarkupPlaceholderTag(true); // hidded line in old portal final FileUploadField xmlfile = new FileUploadField("xmlfile", new ListModel<FileUpload>()); xmlfile.setOutputMarkupId(true); xmlfile.setLabel(ResourceUtils.getModel("label.xmlDataFile")); xmlfile.setOutputMarkupPlaceholderTag(true); xmlfile.setVisibilityAllowed(false); // hidded line in old portal final RadioGroup<Boolean> schema = new RadioGroup<Boolean>("schema", new Model<Boolean>(Boolean.FALSE)); schema.add(new Radio<Boolean>("noschema", new Model<Boolean>(Boolean.FALSE), schema)); schema.add(new Radio<Boolean>("fromschema", new Model<Boolean>(Boolean.TRUE), schema)); schema.setOutputMarkupPlaceholderTag(true); schema.setVisibilityAllowed(false); schema.add(new AjaxFormChoiceComponentUpdatingBehavior() { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { schemaList.setVisibilityAllowed(schema.getModelObject()); xmlfile.setRequired(!xmlfile.isRequired()); target.add(xmlfile); target.add(schemaList); } }); CheckBox privateCheck = new CheckBox("privateScenario"); final CheckBox dataAvailable = new CheckBox("dataAvailable", new Model<Boolean>()); dataAvailable.add(new AjaxFormComponentUpdatingBehavior("onChange") { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { fileContainer.setVisibilityAllowed(dataAvailable.getModelObject()); file.setRequired(!file.isRequired()); target.add(fileContainer); } }); fileContainer.add(file, xmlfile, schema, schemaList); add(groups, title, length, description, privateCheck, dataAvailable, fileContainer); add(new AjaxButton("submitForm", this) { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { FileUpload uploadedFile = file.getFileUpload(); Scenario scenario = ScenarioForm.this.getModelObject(); if (!scenariosFacade.canSaveTitle(scenario.getTitle(), scenario.getScenarioId())) { error(ResourceUtils.getString("error.titleAlreadyInDatabase")); target.add(feedback); return; } else { // loading non-XML scenario file if ((uploadedFile != null) && (!(uploadedFile.getSize() == 0))) { String name = uploadedFile.getClientFileName(); // when uploading from localhost some browsers will specify the entire path, we strip it // down to just the file name name = Strings.lastPathComponent(name, '/'); name = Strings.lastPathComponent(name, '\\'); // File uploaded String filename = name.replace(" ", "_"); scenario.setScenarioName(filename); scenario.setMimetype(uploadedFile.getContentType()); try { scenario.setFileContentStream(uploadedFile.getInputStream()); } catch (IOException e) { log.error(e.getMessage(), e); error("Error while saving data."); target.add(feedback); } } // Creating new scenariosFacade.create(scenario); /* * clean up after upload file, and set model to null or will be problem with page serialization when redirect start - DON'T DELETE IT ! */ ScenarioForm.this.setModelObject(null); window.close(target); } } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(feedback); } }); add(new AjaxButton("closeForm", ResourceUtils.getModel("button.close")) { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { window.close(target); } }.setDefaultFormProcessing(false)); setOutputMarkupId(true); }
From source file:cz.zcu.kiv.eegdatabase.wui.ui.experiments.forms.wizard.AddExperimentEnvironmentForm.java
License:Apache License
private void addTemperature() { TextField<Integer> temperature = new TextField<Integer>("temperature", new PropertyModel<Integer>(model.getObject(), "temperature"), Integer.class); temperature.setLabel(ResourceUtils.getModel("label.temperature")); temperature.setRequired(true);//from w w w . ja v a 2 s. co m temperature.add(RangeValidator.minimum(Integer.valueOf(-273))); final FeedbackPanel feedback = createFeedbackForComponent(temperature, "temperatureFeedback"); add(temperature); add(feedback); }
From source file:cz.zcu.kiv.eegdatabase.wui.ui.scenarios.form.ScenarioForm.java
License:Apache License
public ScenarioForm(String id, IModel<Scenario> model, final FeedbackPanel feedback) { super(id, new CompoundPropertyModel<Scenario>(model)); setMultiPart(true);/*w w w . j a va 2 s . c om*/ Person owner = model.getObject().getPerson(); if (owner == null) { owner = EEGDataBaseSession.get().getLoggedUser(); } model.getObject().setPerson(owner); List<ResearchGroup> choices = researchGroupFacade.getResearchGroupsWhereAbleToWriteInto(owner); if (choices == null || choices.isEmpty()) { choices = Arrays.asList(model.getObject().getResearchGroup()); } DropDownChoice<ResearchGroup> groups = new DropDownChoice<ResearchGroup>("researchGroup", choices, new ChoiceRenderer<ResearchGroup>("title")); groups.setRequired(true); TextField<String> title = new TextField<String>("title"); title.setLabel(ResourceUtils.getModel("label.scenarioTitle")); title.setRequired(true); TextField<Integer> length = new TextField<Integer>("scenarioLength", Integer.class); length.setRequired(true); length.add(RangeValidator.minimum(0)); TextArea<String> description = new TextArea<String>("description"); description.setRequired(true); description.setLabel(ResourceUtils.getModel("label.scenarioDescription")); final WebMarkupContainer fileContainer = new WebMarkupContainer("contailer"); fileContainer.setVisibilityAllowed(false); fileContainer.setOutputMarkupPlaceholderTag(true); /* * TODO file field for xml was not visible in old portal. I dont know why. So I hided it but its implemented and not tested. */ // hidded line in old portal final DropDownChoice<ScenarioSchemas> schemaList = new DropDownChoice<ScenarioSchemas>("schemaList", new Model<ScenarioSchemas>(), scenariosFacade.getListOfScenarioSchemas(), new ChoiceRenderer<ScenarioSchemas>("schemaName", "schemaId")); schemaList.setOutputMarkupPlaceholderTag(true); schemaList.setRequired(true); schemaList.setLabel(ResourceUtils.getModel("label.scenarioSchema")); schemaList.setVisibilityAllowed(false); final FileUploadField file = new FileUploadField("file", new ListModel<FileUpload>()); file.setOutputMarkupId(true); file.setLabel(ResourceUtils.getModel("description.fileType.dataFile")); file.setOutputMarkupPlaceholderTag(true); // hidded line in old portal final FileUploadField xmlfile = new FileUploadField("xmlfile", new ListModel<FileUpload>()); xmlfile.setOutputMarkupId(true); xmlfile.setLabel(ResourceUtils.getModel("label.xmlDataFile")); xmlfile.setOutputMarkupPlaceholderTag(true); xmlfile.setVisibilityAllowed(false); // hidded line in old portal final RadioGroup<Boolean> schema = new RadioGroup<Boolean>("schema", new Model<Boolean>(Boolean.FALSE)); schema.add(new Radio<Boolean>("noschema", new Model<Boolean>(Boolean.FALSE), schema)); schema.add(new Radio<Boolean>("fromschema", new Model<Boolean>(Boolean.TRUE), schema)); schema.setOutputMarkupPlaceholderTag(true); schema.setVisibilityAllowed(false); schema.add(new AjaxFormChoiceComponentUpdatingBehavior() { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { schemaList.setVisibilityAllowed(schema.getModelObject()); xmlfile.setRequired(!xmlfile.isRequired()); target.add(xmlfile); target.add(schemaList); } }); CheckBox privateCheck = new CheckBox("privateScenario"); final CheckBox dataAvailable = new CheckBox("dataAvailable", new Model<Boolean>()); dataAvailable.add(new AjaxFormComponentUpdatingBehavior("onChange") { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { fileContainer.setVisibilityAllowed(dataAvailable.getModelObject()); file.setRequired(!file.isRequired()); target.add(fileContainer); } }); SubmitLink submit = new SubmitLink("submit") { private static final long serialVersionUID = 1L; @Override public void onSubmit() { FileUpload uploadedFile = file.getFileUpload(); Scenario scenario = ScenarioForm.this.getModelObject(); if (!scenariosFacade.canSaveTitle(scenario.getTitle(), scenario.getScenarioId())) { error(ResourceUtils.getString("error.titleAlreadyInDatabase")); return; } else { // loading non-XML scenario file if ((uploadedFile != null) && (!(uploadedFile.getSize() == 0))) { String name = uploadedFile.getClientFileName(); // when uploading from localhost some browsers will specify the entire path, we strip it // down to just the file name name = Strings.lastPathComponent(name, '/'); name = Strings.lastPathComponent(name, '\\'); // File uploaded String filename = name.replace(" ", "_"); scenario.setScenarioName(filename); scenario.setMimetype(uploadedFile.getContentType()); try { scenario.setFileContentStream(uploadedFile.getInputStream()); } catch (IOException e) { log.error(e.getMessage(), e); } } if (scenario.getScenarioId() > 0) { // Editing existing // scenarioTypeDao.update(scenarioType); scenariosFacade.update(scenario); } else { // Creating new scenariosFacade.create(scenario); } /* * clean up after upload file, and set model to null or will be problem with page serialization when redirect start - DON'T DELETE IT ! */ ScenarioForm.this.setModelObject(null); setResponsePage(ScenarioDetailPage.class, PageParametersUtils.getDefaultPageParameters(scenario.getScenarioId())); } } }; fileContainer.add(file, xmlfile, schema, schemaList); add(groups, title, length, description, privateCheck, dataAvailable, submit, fileContainer); }
From source file:net.rrm.ehour.ui.admin.config.panel.MailServerConfigPanel.java
License:Open Source License
@Override protected void onInitialize() { super.onInitialize(); Form<MainConfigBackingBean> form = new Form<>("smtpForm", getPanelModel()); add(form);/*from w w w . j av a 2 s. c om*/ Container disabled = new Container("mailDisabled"); disabled.setVisible(!mailMain.isMailEnabled()); form.add(disabled); // reply sender TextField<String> mailFrom = new TextField<>("config.mailFrom"); mailFrom.setLabel(new ResourceModel("admin.config.mailFrom")); mailFrom.add(EmailAddressValidator.getInstance()); mailFrom.add(new ValidatingFormComponentAjaxBehavior()); form.add(mailFrom); form.add(new AjaxFormComponentFeedbackIndicator("mailFromError", mailFrom)); // smtp server, port, username, pass TextField<String> mailSmtp = new TextField<>("config.mailSmtp"); mailSmtp.setLabel(new ResourceModel("admin.config.mailSmtp")); mailSmtp.add(new ValidatingFormComponentAjaxBehavior()); form.add(new AjaxFormComponentFeedbackIndicator("mailSmtpValidationError", mailSmtp)); form.add(mailSmtp); TextField<Integer> smtpPort = new TextField<>("config.smtpPort"); smtpPort.setLabel(new ResourceModel("admin.config.smtpPort")); smtpPort.add(new ValidatingFormComponentAjaxBehavior()); form.add(new AjaxFormComponentFeedbackIndicator("smtpPortValidationError", mailSmtp)); smtpPort.setType(Integer.class); smtpPort.add(RangeValidator.minimum(0)); form.add(smtpPort); TextField<String> smtpUsername = new TextField<>("config.smtpUsername"); smtpUsername.setLabel(new ResourceModel("admin.config.smtpUsername")); form.add(smtpUsername); PasswordTextField smtpPassword = new PasswordTextField("config.smtpPassword"); smtpPassword.setResetPassword(false); smtpPassword.setRequired(false); smtpPassword.setLabel(new ResourceModel("admin.config.smtpPassword")); form.add(smtpPassword); addTestMailSettingsButton(form); }
From source file:net.rrm.ehour.ui.admin.config.panel.MiscConfigPanel.java
License:Open Source License
private void addMiscComponents(Form<?> form) { // show turnover checkbox CheckBox showTurnover = new CheckBox("config.showTurnover"); showTurnover.setMarkupId("showTurnover"); form.add(showTurnover);//from w ww .ja v a2s. c o m final MainConfigBackingBean configBackingBean = (MainConfigBackingBean) getDefaultModelObject(); // working hours TextField<Float> workHours = new TextField<>("config.completeDayHours", Float.class); workHours.setLabel(new ResourceModel("admin.config.workHours")); workHours.add(new ValidatingFormComponentAjaxBehavior()); workHours.add(RangeValidator.minimum(0f)); workHours.add(RangeValidator.maximum(24f)); workHours.setRequired(true); form.add(new AjaxFormComponentFeedbackIndicator("workHoursValidationError", workHours)); form.add(workHours); // weeks start at DropDownChoice<Date> weekStartsAt; weekStartsAt = new DropDownChoice<>("firstWeekStart", DateUtil .createDateSequence(DateUtil.getDateRangeForWeek(new GregorianCalendar()), new EhourConfigStub()), new WeekDayRenderer(configBackingBean.getLocaleLanguage())); form.add(weekStartsAt); // Timezone DropDownChoice<String> timezone = new DropDownChoice<>("config.timeZone", Lists.newArrayList(DateTimeZone.getAvailableIDs())); form.add(timezone); // pm access rights form.add(new DropDownChoice<>("config.pmPrivilege", Arrays.asList(PmPrivilege.values()), new EnumChoiceRenderer<PmPrivilege>())); // split admin role final Container convertManagersContainer = new Container("convertManagers"); DropDownChoice<UserRole> convertManagersTo = new DropDownChoice<>("convertManagersTo", Lists.newArrayList(UserRole.ADMIN, UserRole.USER), new UserRoleRenderer()); convertManagersContainer.add(convertManagersTo); convertManagersContainer.setVisible(false); form.add(convertManagersContainer); AjaxCheckBox withManagerCheckbox = new AjaxCheckBox("config.splitAdminRole") { @Override protected void onUpdate(AjaxRequestTarget target) { Boolean managersEnabled = this.getModelObject(); boolean showConvert = !managersEnabled && !userService.getUsers(UserRole.MANAGER).isEmpty(); if (convertManagersContainer.isVisible() != showConvert) { convertManagersContainer.setVisible(showConvert); target.add(convertManagersContainer); } } }; withManagerCheckbox.setMarkupId("splitAdminRole"); form.add(withManagerCheckbox); }
From source file:net.rrm.ehour.ui.manage.assignment.form.AssignmentRateRoleFormPartPanel.java
License:Open Source License
public AssignmentRateRoleFormPartPanel(String id, IModel<AssignmentAdminBackingBean> model) { super(id, model); EhourConfig config = EhourWebSession.getEhourConfig(); // add role//from www.j a v a 2 s.com TextField<String> role = new TextField<>("projectAssignment.role"); add(role); // add hourly rate TextField<Float> hourlyRate = new TextField<>("projectAssignment.hourlyRate", new PropertyModel<Float>(model, "projectAssignment.hourlyRate")); hourlyRate.setLabel(new ResourceModel("admin.assignment.rate")); hourlyRate.setType(Float.class); hourlyRate.add(new ValidatingFormComponentAjaxBehavior()); hourlyRate.add(RangeValidator.minimum(0f)); add(hourlyRate); add(new AjaxFormComponentFeedbackIndicator("rateValidationError", hourlyRate)); // and currency add(new Label("currency", Currency.getInstance(config.getCurrency()).getSymbol(config.getCurrency()))); }
From source file:net.rrm.ehour.ui.manage.assignment.form.AssignmentTypeFormPartPanel.java
License:Open Source License
private void addAssignmentType(IModel<AssignmentAdminBackingBean> model) { List<ProjectAssignmentType> assignmentTypes = projectAssignmentService.getProjectAssignmentTypes(); final PropertyModel<Boolean> showAllottedHoursModel = new PropertyModel<>(model, "showAllottedHours"); final PropertyModel<Boolean> showOverrunHoursModel = new PropertyModel<>(model, "showOverrunHours"); // assignment type final DropDownChoice<ProjectAssignmentType> assignmentTypeChoice = new DropDownChoice<>( "projectAssignment.assignmentType", assignmentTypes, new ProjectAssignmentTypeRenderer()); assignmentTypeChoice.setRequired(true); assignmentTypeChoice.setNullValid(false); assignmentTypeChoice.setLabel(new ResourceModel("admin.assignment.type")); assignmentTypeChoice.add(new ValidatingFormComponentAjaxBehavior()); add(assignmentTypeChoice);/*from w w w . j a va 2s.c o m*/ add(new AjaxFormComponentFeedbackIndicator("typeValidationError", assignmentTypeChoice)); // allotted hours final TextField<Float> allottedHours = new RequiredTextField<>("projectAssignment.allottedHours", new PropertyModel<Float>(model, "projectAssignment.allottedHours")); allottedHours.setType(float.class); allottedHours.add(new ValidatingFormComponentAjaxBehavior()); allottedHours.add(RangeValidator.minimum(0f)); allottedHours.setOutputMarkupId(true); allottedHours.setLabel(new ResourceModel("admin.assignment.timeAllotted")); allottedHours.setEnabled(showAllottedHoursModel.getObject()); // allotted hours row final WebMarkupContainer allottedRow = new WebMarkupContainer("allottedRow"); allottedRow.setOutputMarkupId(true); allottedRow.add(allottedHours); allottedRow.add(new AjaxFormComponentFeedbackIndicator("allottedHoursValidationError", allottedHours)); allottedRow .add(new DynamicAttributeModifier("style", new Model<>("display: none;"), showAllottedHoursModel)); add(allottedRow); // overrun hours final TextField<Float> overrunHours = new RequiredTextField<>("projectAssignment.allowedOverrun", new PropertyModel<Float>(model, "projectAssignment.allowedOverrun")); overrunHours.setType(float.class); overrunHours.add(new ValidatingFormComponentAjaxBehavior()); overrunHours.add(RangeValidator.minimum(0f)); overrunHours.setOutputMarkupId(true); overrunHours.setEnabled(showOverrunHoursModel.getObject()); overrunHours.setLabel(new ResourceModel("admin.assignment.allowedOverrun")); // overrun hours row final WebMarkupContainer overrunRow = new WebMarkupContainer("overrunRow"); overrunRow.setOutputMarkupId(true); overrunRow.add(overrunHours); overrunRow.add(new AjaxFormComponentFeedbackIndicator("overrunHoursValidationError", overrunHours)); overrunRow.add(new DynamicAttributeModifier("style", new Model<>("display: none;"), showOverrunHoursModel)); add(overrunRow); // notify PM when possible CheckBox notifyPm = new CheckBox("projectAssignment.notifyPm"); notifyPm.setMarkupId("notifyPm"); notifyPm.add(new DynamicAttributeModifier("style", new Model<>("display: none;"), new PropertyModel<Boolean>(model, "notifyPmEnabled"))); notifyPm.setOutputMarkupId(true); Label notifyDisabled = new Label("notifyDisabled", new ResourceModel("admin.assignment.cantNotify")); notifyDisabled.add(new DynamicAttributeModifier("style", new Model<>("display: none;"), new PropertyModel<Boolean>(model, "notifyPmEnabled"), true)); notifyDisabled.setOutputMarkupId(true); // notify PM row final WebMarkupContainer notifyPmRow = new WebMarkupContainer("notifyPmRow"); notifyPmRow.setOutputMarkupId(true); notifyPmRow.add(notifyPm); notifyPmRow.add(notifyDisabled); notifyPmRow .add(new DynamicAttributeModifier("style", new Model<>("display: none;"), showAllottedHoursModel)); add(notifyPmRow); assignmentTypeChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = 1L; protected void onUpdate(AjaxRequestTarget target) { // to disable the required validation allottedHours.setEnabled(showAllottedHoursModel.getObject()); overrunHours.setEnabled(showOverrunHoursModel.getObject()); target.add(allottedHours); target.add(overrunHours); // show/hide rows dependent on the assignment type selected target.add(allottedRow); target.add(overrunRow); target.add(notifyPmRow); } }); listeners = new Component[] { notifyPm, notifyDisabled }; }