public StreamedContent getPhoto() { byte[] photo = recipe.getPhoto(); if (photo != null && photo.length > 0) { return new DefaultStreamedContent(new ByteArrayInputStream(photo)); } return null; }
private void refreshRecipe() { recipe = new Recipe(); recipe.setCategory(new Category()); recipe.setCookingMethod(new Cookingmethod()); recipe.setCuisine(new Cuisine()); recipe.setCookingTime(30); recipe.setPrepTime(15); recipe.setServingQty(4); HttpSession session = FacesUtil.getSession(); User user = (User) session.getAttribute("user"); recipe.setUserId(user); recipe.setCreatedDate("2014"); recipe.setStatus("requested"); recipe.setRecipeingredientList(ingredients); }
public StreamedContent getImage() throws IOException { FacesContext context = FacesContext.getCurrentInstance(); if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) { // So, we're rendering the HTML. Return a stub StreamedContent so that it will generate right // URL. return new DefaultStreamedContent(); } else { // So, browser is requesting the image. Return a real StreamedContent with the image bytes. Integer recipeId = Integer.parseInt(context.getExternalContext().getRequestParameterMap().get("recipeId")); Recipe recipe = service.getById(recipeId); byte[] photo = recipe.getPhoto(); if (photo == null) { return null; } return new DefaultStreamedContent(new ByteArrayInputStream(photo)); } }
public void upload(FileUploadEvent event) { UploadedFile file = event.getFile(); if (file != null) { recipe.setPhoto(file.getContents()); } }