public String createNewMenu() { Menu menu = new Menu(); menu.setMenuName(menuName); if (!resources.persistMenu(menu)) { FacesContext.getCurrentInstance() .addMessage( null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "An error occurred!", null)); return "createFail"; } FacesContext.getCurrentInstance() .addMessage( null, new FacesMessage( FacesMessage.SEVERITY_INFO, "New Menu Item \"" + menu.getMenuName() + "\" created!", null)); return "createSuccess"; }
public String getFoodsStr(Menu menu) { String delim = ""; String result = ""; for (Food food : menu.getFoods()) { result += delim + food.getFoodName(); delim = ", "; } return result; }
public String uploadFile() { Menu menu = resources.getMenu(menuId); if (file == null) return "failure"; String basePath = Util.getBasePath(); String filePath = Paths.get(basePath, Util.getFileName(file.getSubmittedFileName())).toString(); File saveFile = new File(filePath); if (!saveFile.exists()) { try { saveFile.createNewFile(); FileOutputStream os = new FileOutputStream(saveFile); ByteStreams.copy(file.getInputStream(), os); os.close(); } catch (Exception e) { e.printStackTrace(); return "failure"; } } menu.setImgPath(Paths.get("img", Util.getFileName(file.getSubmittedFileName())).toString()); resources.updateMenu(menu); return "success"; }
public String setDescFor(Menu menu) { menu.setDescription(getEditText()); setEditText(""); resources.updateMenu(menu); return "success"; }