Пример #1
0
  public void create() {
    service.create(recipe);

    MessagesUtil.setGlobalInfoMessage(MessagesUtil.getValue("createRecipeSuccessful"));

    ingredients = new ArrayList<>();
    refreshRecipeIngredient();
    refreshRecipe();
  }
Пример #2
0
  public Rating getUserRating(User user) {
    this.recipe = service.getById(this.recipe.getId());
    List<Rating> ratingList = this.recipe.getRatingList();
    if (ratingList != null && !ratingList.isEmpty()) {

      for (Rating rating : ratingList) {
        User rater = rating.getUserId();
        if (rater.getId() == user.getId()) {
          return rating;
        }
      }
    }

    return null;
  }
Пример #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));
    }
  }
Пример #4
0
 public List<Recipe> getAll() {
   return service.getAll();
 }
Пример #5
0
  public String showRecipe(Integer id) {
    recipe = service.getById(id);

    return "showrecipe";
  }