From af7c49713a1500cc18d989958202f4a52a986a27 Mon Sep 17 00:00:00 2001 From: Tim Holloway Date: Thu, 6 Jan 2022 09:49:07 -0500 Subject: [PATCH] Save with bad ingkey, print page fixes --- .../com/mousetech/gourmetj/IngredientUI.java | 9 +- .../java/com/mousetech/gourmetj/JSFUtils.java | 10 + .../mousetech/gourmetj/RecipeDetailBean.java | 35 +++- .../META-INF/resources/detailEdit.xhtml | 38 +++- .../META-INF/resources/recipePrint.xhtml | 172 +++++++++++------- 5 files changed, 186 insertions(+), 78 deletions(-) diff --git a/src/main/java/com/mousetech/gourmetj/IngredientUI.java b/src/main/java/com/mousetech/gourmetj/IngredientUI.java index 62f7118..280266a 100644 --- a/src/main/java/com/mousetech/gourmetj/IngredientUI.java +++ b/src/main/java/com/mousetech/gourmetj/IngredientUI.java @@ -5,9 +5,6 @@ import com.mousetech.gourmetj.persistence.model.IngredientIF; import com.mousetech.gourmetj.persistence.model.Recipe; import com.mousetech.gourmetj.persistence.model.Shopcat; -import net.bytebuddy.asm.Advice.This; - -import com.mousetech.gourmetj.IngredientDigester; import com.mousetech.gourmetj.IngredientDigester.IngredientAmountFormat; /** @@ -26,9 +23,13 @@ public class IngredientUI implements IngredientIF { /** * Constructor. * - * @param ingredient + * @param ingredient Ingredient that we facade. If null, + * constructs a dummy Ingredient (example, for group item). */ public IngredientUI(Ingredient ingredient) { + if ( ingredient == null ) { + ingredient = new Ingredient(); + } this.ingredient = ingredient; } diff --git a/src/main/java/com/mousetech/gourmetj/JSFUtils.java b/src/main/java/com/mousetech/gourmetj/JSFUtils.java index f1b9b8c..4398cca 100644 --- a/src/main/java/com/mousetech/gourmetj/JSFUtils.java +++ b/src/main/java/com/mousetech/gourmetj/JSFUtils.java @@ -84,7 +84,17 @@ public class JSFUtils { .getExternalContext().getFlash()); } + /** + * Look in Flash scope for item. + * + * @param key Item to retrieve + * @return Item, or null if not in Flash OR Flash not active + */ public static Object getFlash(String key) { + Flash flash = flashScope(); + if ( flash == null ) { + return null; + } return flashScope().get(key); } diff --git a/src/main/java/com/mousetech/gourmetj/RecipeDetailBean.java b/src/main/java/com/mousetech/gourmetj/RecipeDetailBean.java index e31b71d..e0bd569 100644 --- a/src/main/java/com/mousetech/gourmetj/RecipeDetailBean.java +++ b/src/main/java/com/mousetech/gourmetj/RecipeDetailBean.java @@ -231,7 +231,7 @@ public class RecipeDetailBean implements Serializable { */ if (this.recipe == null) { Long rid = - (Long) JSFUtils.flashScope().get("recipeID"); + (Long) JSFUtils.getFlash("recipeID"); if (rid != null) { this.recipe = loadRecipe(rid); } else { @@ -704,7 +704,7 @@ public class RecipeDetailBean implements Serializable { JSFUtils.addErrorMessage( "No Shopping Category is defined for Ingredient Key " + ingKey); - return false; + //return false; } ing.setShopCat(scat); @@ -1008,4 +1008,35 @@ public class RecipeDetailBean implements Serializable { long now = new java.util.Date().getTime(); return String.valueOf(now); } + + //*** Add Group + + private String newGroupName; + + /** + * @return the newGroupName + */ + public String getNewGroupName() { + return newGroupName; + } + + /** + * @param newGroupName the newGroupName to set + */ + public void setNewGroupName(String newGroupName) { + this.newGroupName = newGroupName; + } + + /** + * Add new group to bottom of model as AJAX operation. + * @return null + */ + public String doAddGroup() { + IngredientUI iui = new IngredientUI(null); + iui.setIngGroup(true); + iui.setItem(this.getNewGroupName()); + List ingUIList = this.getWrappedIngredients(); + ingUIList.add(iui); + return null; + } } diff --git a/src/main/resources/META-INF/resources/detailEdit.xhtml b/src/main/resources/META-INF/resources/detailEdit.xhtml index 7c26e01..6837053 100644 --- a/src/main/resources/META-INF/resources/detailEdit.xhtml +++ b/src/main/resources/META-INF/resources/detailEdit.xhtml @@ -165,8 +165,9 @@ render="ingredientTable" /> - @@ -274,9 +276,7 @@ /> - + E @@ -287,6 +287,7 @@ update="editShopcatDlg" oncomplete="PF('editShopcatDlg').show()" title="Edit the shopping category for ing. key" + rendered="#{not item.ingGroup}" /> @@ -351,6 +352,7 @@ @@ -359,6 +361,32 @@ /> + + + + + + + + + + + + diff --git a/src/main/resources/META-INF/resources/recipePrint.xhtml b/src/main/resources/META-INF/resources/recipePrint.xhtml index 8a41317..d54b252 100644 --- a/src/main/resources/META-INF/resources/recipePrint.xhtml +++ b/src/main/resources/META-INF/resources/recipePrint.xhtml @@ -9,80 +9,118 @@ Gourmet Recipe Manager - -    - - - - - - - - - - - - - - - - - + + - - + - - - - - - - - + - - - - - - + + + + + - + + + + + - - - - - - - + + + + + + + + Amt. + + + + + Units + + + + + Item + + + + + + Opt. + + + + + + + - + + + + + + + + + + + + + + \ No newline at end of file