Exemple #1
0
  public StreamedContent getPhoto() {
    byte[] photo = recipe.getPhoto();
    if (photo != null && photo.length > 0) {
      return new DefaultStreamedContent(new ByteArrayInputStream(photo));
    }

    return null;
  }
Exemple #2
0
  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);
  }
Exemple #3
0
  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));
    }
  }
Exemple #4
0
 public void upload(FileUploadEvent event) {
   UploadedFile file = event.getFile();
   if (file != null) {
     recipe.setPhoto(file.getContents());
   }
 }