public void create() { service.create(recipe); MessagesUtil.setGlobalInfoMessage(MessagesUtil.getValue("createRecipeSuccessful")); ingredients = new ArrayList<>(); refreshRecipeIngredient(); refreshRecipe(); }
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; }
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 List<Recipe> getAll() { return service.getAll(); }
public String showRecipe(Integer id) { recipe = service.getById(id); return "showrecipe"; }