List of usage examples for org.apache.wicket.markup.html.form Form setMaxSize
public void setMaxSize(final Bytes maxSize)
From source file:ca.travelagency.config.CompanyPage.java
License:Apache License
private Form<Void> uploadForm() { Form<Void> form = new Form<Void>(UPLOAD_FORM) { private static final long serialVersionUID = 1L; @Override// w w w. j a v a 2 s.c o m protected void onSubmit() { FileUpload fileUpload = fileUploadField.getFileUpload(); if (fileUpload == null) { return; } String code = ApplicationProperties.make().getCode(); File companyLogoFile = UploadUtils.getCompanyLogoFile(code); try { companyLogoFile.createNewFile(); fileUpload.writeTo(companyLogoFile); } catch (Exception e) { throw new RuntimeException("Unable to write logo image", e); } } }; form.setMultiPart(true); form.setMaxSize(Bytes.kilobytes(100)); form.add(new ComponentFeedbackPanel(FEEDBACK, form)); fileUploadField = new FileUploadField(UPLOAD_FIELD, new ListModel<FileUpload>()); form.add(fileUploadField); return form; }
From source file:com.evolveum.midpoint.web.page.admin.users.PageUser.java
License:Apache License
private void initLayout() { Form mainForm = new Form(ID_MAIN_FORM); mainForm.setMaxSize(MidPointApplication.USER_PHOTO_MAX_FILE_SIZE); mainForm.setMultiPart(true);//w w w. ja v a 2s.c o m add(mainForm); initSummaryInfo(mainForm); PrismObjectPanel userForm = new PrismObjectPanel(ID_USER_FORM, userModel, new PackageResourceReference(ImgResources.class, ImgResources.USER_PRISM), mainForm) { @Override protected IModel<String> createDescription(IModel<ObjectWrapper> model) { return createStringResource("pageUser.description"); } }; mainForm.add(userForm); WebMarkupContainer accounts = new WebMarkupContainer(ID_ACCOUNTS); accounts.setOutputMarkupId(true); mainForm.add(accounts); initAccounts(accounts); WebMarkupContainer assignments = new WebMarkupContainer(ID_ASSIGNMENTS); assignments.setOutputMarkupId(true); mainForm.add(assignments); initAssignments(assignments); WebMarkupContainer tasks = new WebMarkupContainer(ID_TASKS); tasks.setOutputMarkupId(true); mainForm.add(tasks); initTasks(tasks); initButtons(mainForm); initResourceModal(); initAssignableModal(); initConfirmationDialogs(); }
From source file:com.evolveum.midpoint.web.page.PageTest.java
License:Apache License
private void initLayout() { Form form = new Form("form"); form.setMaxSize(Bytes.kilobytes(192)); // form.setMultiPart(true); add(form);//from ww w. j av a2s . co m FileUploadField fileUpload = new FileUploadField("fileInput"); form.add(fileUpload); AjaxSubmitButton save = new AjaxSubmitButton("save", createStringResource("pageUser.button.save")) { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { setResponsePage(PageUsers.class); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(getFeedbackPanel()); } }; form.add(save); }
From source file:eu.esdihumboldt.hale.server.templates.war.components.TemplateUploadForm.java
License:Open Source License
/** * Constructor//from w ww. j a v a 2 s . c om * * @param id the component ID * @param templateId the identifier of the template to update, or * <code>null</code> to create a new template */ public TemplateUploadForm(String id, String templateId) { super(id); this.templateId = templateId; Form<Void> form = new Form<Void>("upload") { private static final long serialVersionUID = 716487990605324922L; @Override protected void onSubmit() { List<FileUpload> uploads = file.getFileUploads(); if (uploads != null && !uploads.isEmpty()) { final boolean newTemplate = TemplateUploadForm.this.templateId == null; final String templateId; final File dir; File oldContent = null; if (newTemplate) { // attempt to reserve template ID Pair<String, File> template; try { template = templates.reserveResource(determinePreferredId(uploads)); } catch (ScavengerException e) { error(e.getMessage()); return; } templateId = template.getFirst(); dir = template.getSecond(); } else { templateId = TemplateUploadForm.this.templateId; dir = new File(templates.getHuntingGrounds(), templateId); // archive old content try { Path tmpFile = Files.createTempFile("hale-template", ".zip"); try (OutputStream out = Files.newOutputStream(tmpFile); ZipOutputStream zos = new ZipOutputStream(out)) { IOUtils.zipDirectory(dir, zos); } oldContent = tmpFile.toFile(); } catch (IOException e) { log.error("Error saving old template content to archive", e); } // delete old content try { FileUtils.cleanDirectory(dir); } catch (IOException e) { log.error("Error deleting old template content", e); } } try { for (FileUpload upload : uploads) { if (isZipFile(upload)) { // extract uploaded file IOUtils.extract(dir, new BufferedInputStream(upload.getInputStream())); } else { // copy uploaded file File target = new File(dir, upload.getClientFileName()); ByteStreams.copy(upload.getInputStream(), new FileOutputStream(target)); } } // trigger scan after upload if (newTemplate) { templates.triggerScan(); } else { templates.forceUpdate(templateId); } TemplateProject ref = templates.getReference(templateId); if (ref != null && ref.isValid()) { info("Successfully uploaded project"); boolean infoUpdate = (updateInfo != null) ? (updateInfo.getModelObject()) : (false); onUploadSuccess(this, templateId, ref.getProjectInfo(), infoUpdate); } else { if (newTemplate) { templates.releaseResourceId(templateId); } else { restoreContent(dir, oldContent); } error((ref != null) ? (ref.getNotValidMessage()) : ("Uploaded files could not be loaded as HALE project")); } } catch (Exception e) { if (newTemplate) { templates.releaseResourceId(templateId); } else { restoreContent(dir, oldContent); } log.error("Error while uploading file", e); error("Error saving the file"); } } else { warn("Please provide a file for upload"); } } @Override protected void onFileUploadException(FileUploadException e, Map<String, Object> model) { if (e instanceof SizeLimitExceededException) { final String msg = "Only files up to " + bytesToString(getMaxSize(), Locale.US) + " can be uploaded."; error(msg); } else { final String msg = "Error uploading the file: " + e.getLocalizedMessage(); error(msg); log.warn(msg, e); } } }; add(form); // multipart always needed for uploads form.setMultiPart(true); // max size for upload if (UserUtil.isAdmin()) { // admin max upload size form.setMaxSize(Bytes.megabytes(100)); } else { // normal user max upload size // TODO differentiate between logged in and anonymous user? form.setMaxSize(Bytes.megabytes(15)); } // Add file input field for multiple files form.add(file = new FileUploadField("file")); file.add(new IValidator<List<FileUpload>>() { private static final long serialVersionUID = -5668788086384105101L; @Override public void validate(IValidatable<List<FileUpload>> validatable) { if (validatable.getValue().isEmpty()) { validatable.error(new ValidationError("No source files specified.")); } } }); // add anonym/recaptcha panel boolean loggedIn = UserUtil.getLogin() != null; WebMarkupContainer anonym = new WebMarkupContainer("anonym"); if (loggedIn) { anonym.add(new WebMarkupContainer("recaptcha")); } else { anonym.add(new RecaptchaPanel("recaptcha")); } anonym.add( new BookmarkablePageLink<>("login", ((BaseWebApplication) getApplication()).getLoginPageClass())); anonym.setVisible(!loggedIn); form.add(anonym); // update panel WebMarkupContainer update = new WebMarkupContainer("update"); update.setVisible(templateId != null); updateInfo = new CheckBox("updateInfo", Model.of(true)); update.add(updateInfo); form.add(update); // feedback panel form.add(new BootstrapFeedbackPanel("feedback")); }
From source file:eu.esdihumboldt.hale.server.templates.war.components.UploadForm.java
License:Open Source License
/** * @see Panel#Panel(String)//from ww w . j a v a2 s.co m */ public UploadForm(String id) { super(id); Form<Void> form = new Form<Void>("upload") { private static final long serialVersionUID = 716487990605324922L; @Override protected void onSubmit() { // attempt to reserve template ID Pair<String, File> template; try { template = templates.reserveResource(null); } catch (ScavengerException e) { error(e.getMessage()); return; } final String templateId = template.getFirst(); final File dir = template.getSecond(); try { List<FileUpload> uploads = file.getFileUploads(); if (uploads != null && !uploads.isEmpty()) { for (FileUpload upload : uploads) { if (isZipFile(upload)) { // extract uploaded file IOUtils.extract(dir, new BufferedInputStream(upload.getInputStream())); } else { // copy uploaded file File target = new File(dir, upload.getClientFileName()); ByteStreams.copy(upload.getInputStream(), new FileOutputStream(target)); } } // trigger scan after upload templates.triggerScan(); ProjectReference<Void> ref = templates.getReference(templateId); if (ref != null && ref.getProjectInfo() != null) { info("Successfully uploaded project"); onUploadSuccess(this, templateId, ref.getProjectInfo()); } else { templates.releaseResourceId(templateId); error("Uploaded files could not be loaded as HALE project"); } } else { templates.releaseResourceId(templateId); warn("Please provide a file for upload"); } } catch (Exception e) { templates.releaseResourceId(templateId); log.error("Error while uploading file", e); error("Error saving the file"); } } @Override protected void onFileUploadException(FileUploadException e, Map<String, Object> model) { if (e instanceof SizeLimitExceededException) { final String msg = "Only files up to " + bytesToString(getMaxSize(), Locale.US) + " can be uploaded."; error(msg); } else { final String msg = "Error uploading the file: " + e.getLocalizedMessage(); error(msg); log.warn(msg, e); } } }; add(form); // multipart always needed for uploads form.setMultiPart(true); // max size for upload form.setMaxSize(Bytes.megabytes(1)); // Add file input field for multiple files form.add(file = new FileUploadField("file")); file.add(new IValidator<List<FileUpload>>() { private static final long serialVersionUID = -5668788086384105101L; @Override public void validate(IValidatable<List<FileUpload>> validatable) { if (validatable.getValue().isEmpty()) { validatable.error(new ValidationError("No source files specified.")); } } }); // add anonym/recaptcha panel boolean loggedIn = UserUtil.getLogin() != null; WebMarkupContainer anonym = new WebMarkupContainer("anonym"); if (loggedIn) { anonym.add(new WebMarkupContainer("recaptcha")); } else { anonym.add(new RecaptchaPanel("recaptcha")); } anonym.add( new BookmarkablePageLink<>("login", ((BaseWebApplication) getApplication()).getLoginPageClass())); anonym.setVisible(!loggedIn); form.add(anonym); // feedback panel form.add(new BootstrapFeedbackPanel("feedback")); }
From source file:eu.uqasar.web.pages.tree.projects.ProjectImportPage.java
License:Apache License
public ProjectImportPage(PageParameters parameters) { super(parameters); upload = new FileUploadField("file"); final Form<?> form = new Form<Void>("form") { private static final long serialVersionUID = -8541751079487127243L; @Override//from www. j a v a 2 s . c o m protected void onSubmit() { Project p = null; try { FileUpload file = upload.getFileUpload(); if (file == null) { logger.info("File upload failed"); error = true; } else { if (file.getSize() > Bytes.kilobytes(MAX_SIZE).bytes()) { logger.info("File is too big"); error = true; } else { String content = file.getContentType(); if (content != null) { logger.info("Parser called"); p = parseProject(file, content); p = (Project) treeNodeService.create(p); // set company to qmodel user = UQasar.getSession().getLoggedInUser(); if (user != null && user.getCompany() != null) { p.setCompany(user.getCompany()); } } else { logger.info("Upload file is invalid"); error = true; } } } } catch (uQasarException ex) { if (ex.getMessage().contains("nodeKey")) { error = true; logger.info("duplicated nodeKey"); errorMessage = "import.key.unique"; } } catch (Exception ex) { error = true; logger.error(ex.getMessage(), ex); } finally { PageParameters parameters = new PageParameters(); if (error) { parameters.add(BasePage.LEVEL_PARAM, FeedbackMessage.ERROR); if (errorMessage != null && errorMessage.contains("key")) { parameters.add(QModelImportPage.MESSAGE_PARAM, getLocalizer().getString(errorMessage, this)); } else { parameters.add(BasePage.MESSAGE_PARAM, getLocalizer().getString("import.importError", this)); } setResponsePage(ProjectImportPage.class, parameters); } else { parameters.add(BasePage.LEVEL_PARAM, FeedbackMessage.SUCCESS); parameters.add(BasePage.MESSAGE_PARAM, getLocalizer().getString("import.importMessage", this)); // TODO what if p == null? parameters.add("project-key", p != null ? p.getNodeKey() : "?"); setResponsePage(ProjectViewPage.class, parameters); } } } }; form.add(upload); form.setMaxSize(Bytes.kilobytes(MAX_SIZE)); form.add(new Label("max", new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 3532428309651830468L; @Override public String getObject() { return form.getMaxSize().toString(); } })); form.add(new UploadProgressBar("progress", form, upload)); form.add(new Button("uploadButton", new StringResourceModel("upload.button", this, null))); add(form); }
From source file:it.av.eatt.web.page.RistoranteEditPicturePage.java
License:Apache License
/** * @param parameters// w ww. java2 s . c om * @throws JackWicketException */ public RistoranteEditPicturePage(PageParameters parameters) throws JackWicketException { String ristoranteId = parameters.getString("ristoranteId", ""); if (StringUtils.isNotBlank(ristoranteId)) { this.ristorante = ristoranteService.getByID(ristoranteId); } else { setRedirect(true); setResponsePage(getApplication().getHomePage()); } form = new Form<Ristorante>("ristorantePicturesForm"); add(form); form.setOutputMarkupId(true); form.setMultiPart(true); form.setMaxSize(Bytes.megabytes(1)); uploadField = new FileUploadField("uploadField"); form.add(uploadField); form.add(new UploadProgressBar("progressBar", form)); form.add(new SubmitButton("submitForm", form)); picturesList = new ListView<RistorantePicture>("picturesList", ristorante.getPictures()) { @Override protected void populateItem(final ListItem<RistorantePicture> item) { //Button disabled, because the getPicture is not yet implemented item.add(new AjaxFallbackButton("publish-unpublish", form) { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { item.getModelObject().setActive(!item.getModelObject().isActive()); try { ristorantePictureService.save(item.getModelObject()); ristorante = ristoranteService.getByID(ristorante.getId()); } catch (JackWicketException e) { error(getString("genericErrorMessage")); } if (target != null) { target.addComponent(getFeedbackPanel()); target.addComponent(form); } } @Override protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); if (item.getModelObject().isActive()) { tag.getAttributes().put("title", getString("button.unpublish")); tag.getAttributes().put("class", "unpublishPictureButton"); } else { tag.getAttributes().put("title", getString("button.publish")); tag.getAttributes().put("class", "publishPictureButton"); } } }.setVisible(false)); item.add(new AjaxFallbackButton("remove", form) { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { try { RistorantePicture picture = item.getModelObject(); ristorante.getPictures().remove(picture); ristoranteService.updateNoRevision(ristorante); ristorantePictureService.remove(picture); ristorante = ristoranteService.getByID(ristorante.getId()); } catch (JackWicketException e) { error(getString("genericErrorMessage")); } if (target != null) { target.addComponent(getFeedbackPanel()); target.addComponent(form); } } }); item.add(new Image("picture", new DynamicImageResource() { @Override protected byte[] getImageData() { return item.getModelObject().getPicture(); } })); } }; picturesList.setOutputMarkupId(true); picturesList.setReuseItems(true); form.add(picturesList); }
From source file:it.av.youeat.web.page.BaseEaterAccountPage.java
License:Apache License
public BaseEaterAccountPage(PageParameters pageParameters) { if (!pageParameters.getNamedKeys().contains(YoueatHttpParams.YOUEAT_ID)) { throw new YoueatException("Missing user id"); }//from w ww .jav a2 s. c o m String eaterId = pageParameters.get(YoueatHttpParams.YOUEAT_ID).toString(""); eater = eaterService.getByID(eaterId); accountForm = new Form<Eater>("account", new CompoundPropertyModel<Eater>(eater)); accountForm.setOutputMarkupId(true); add(accountForm); accountForm.add(new RequiredTextField<String>("firstname")); accountForm.add(new RequiredTextField<String>("lastname")); DropDownChoice<Country> country = new DropDownChoice<Country>(Eater.COUNTRY, countryService.getAll()); country.setRequired(true); accountForm.add(country); accountForm.add(new DropDownChoice<Language>("language", languageService.getAll(), new LanguageRenderer())); Form formAvatar = new Form("formAvatar"); add(formAvatar); formAvatar.setOutputMarkupId(true); formAvatar.setMultiPart(true); formAvatar.setMaxSize(Bytes.megabytes(1)); FileUploadField uploadField = new FileUploadField("uploadField"); formAvatar.add(uploadField); // formAvatar.add(new UploadProgressBar("progressBar", accountForm)); formAvatar.add(new SubmitAvatarButton("submitForm", formAvatar)); imagecontatiner = new WebMarkupContainer("imageContainer"); imagecontatiner.setOutputMarkupId(true); formAvatar.add(imagecontatiner); avatar = new NonCachingImage("avatar", new ImageAvatarResource(eater)); avatar.setOutputMarkupPlaceholderTag(true); imagecontatiner.add(avatar); avatarDefault = ImagesAvatar.getAvatar("avatarDefault", eater, this, true); if (eater.getAvatar() != null) { avatarDefault.setVisible(false); } else { avatar.setVisible(false); } imagecontatiner.add(avatarDefault); }
From source file:org.apache.openmeetings.web.common.UploadableProfileImagePanel.java
License:Apache License
public UploadableProfileImagePanel(String id, final long userId) { super(id, userId); final Form<Void> form = new Form<Void>("form"); form.setMultiPart(true);/*from w w w. j av a2s . co m*/ form.setMaxSize(Bytes.bytes(getBean(ConfigurationDao.class).getMaxUploadSize())); // Model is necessary here to avoid writing image to the User object form.add(fileUploadField = new FileUploadField("image", new IModel<List<FileUpload>>() { private static final long serialVersionUID = 1L; //FIXME this need to be eliminated @Override public void detach() { } @Override public void setObject(List<FileUpload> object) { } @Override public List<FileUpload> getObject() { return null; } })); form.add(new UploadProgressBar("progress", form, fileUploadField)); fileUploadField.add(new AjaxFormSubmitBehavior(form, "change") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target) { FileUpload fu = fileUploadField.getFileUpload(); if (fu != null) { StoredFile sf = new StoredFile(fu.getClientFileName()); if (sf.isImage()) { boolean asIs = sf.isAsIs(); try { //FIXME need to work with InputStream !!! getBean(GenerateImage.class).convertImageUserProfile(fu.writeToTempFile(), userId, asIs); } catch (Exception e) { // TODO display error log.error("Error", e); } } else { //TODO display error } } update(); target.add(profile, form); } }); add(form.setOutputMarkupId(true)); add(BootstrapFileUploadBehavior.INSTANCE); }
From source file:org.cyclop.web.panels.queryimport.QueryImportPanel.java
License:Apache License
private Form<?> initFileUpload(final ImportOptions importOptions) { final FileUploadField scriptFile = new FileUploadField("scriptFile"); final Form<?> form = new Form<Void>("form") { @Override// ww w . j av a 2s .c o m protected void onSubmit() { } }; form.setMaxSize(Bytes.megabytes(conf.queryImport.maxFileSizeMb)); add(form); form.add(scriptFile); form.add(new AjaxButton("ajaxSubmit") { @Override protected void onError(AjaxRequestTarget target, Form<?> form) { LOG.info("Got error on import upload: {}", form); sendJsResponse(target, ErrorCodes.FILE_SIZE_LIMIT.name()); } @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { FileUpload upload = scriptFile.getFileUpload(); if (upload == null) { return; } executeImport(target, importOptions, upload); } }); return form; }