コード例 #1
0
 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";
 }
コード例 #2
0
  public String getFoodsStr(Menu menu) {
    String delim = "";
    String result = "";

    for (Food food : menu.getFoods()) {
      result += delim + food.getFoodName();
      delim = ", ";
    }

    return result;
  }
コード例 #3
0
  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";
  }
コード例 #4
0
 public String setDescFor(Menu menu) {
   menu.setDescription(getEditText());
   setEditText("");
   resources.updateMenu(menu);
   return "success";
 }