Save with bad ingkey, print page fixes

This commit is contained in:
Tim Holloway 2022-01-06 09:49:07 -05:00
parent bc368f084c
commit af7c49713a
5 changed files with 186 additions and 78 deletions

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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<IngredientUI> ingUIList = this.getWrappedIngredients();
ingUIList.add(iui);
return null;
}
}

View File

@ -165,8 +165,9 @@
render="ingredientTable"
/>
</p:commandButton>
<p:button value="Add Group"
disabled="true"
<p:commandButton
value="Add Group"
onclick="PF('addGroupDlg').show()"
/>
<p:button
value="Add Recipe As Ingredient"
@ -255,6 +256,7 @@
id="ingOpt"
value="#{item.optionalCB}"
rendered="#{not item.ingGroup}"
title="Optional item"
/>
</p:column>
<p:column style="width: 13em">
@ -274,9 +276,7 @@
/>
</p:inputText>
</p:column>
<p:column
style="width: 2em"
>
<p:column style="width: 2em">
<f:facet name="header">
E
</f:facet>
@ -287,6 +287,7 @@
update="editShopcatDlg"
oncomplete="PF('editShopcatDlg').show()"
title="Edit the shopping category for ing. key"
rendered="#{not item.ingGroup}"
/>
</p:column>
<p:column>
@ -351,6 +352,7 @@
</p:tab>
</p:tabView>
<p:commandButton id="doSave" value="Save"
icon="pi pi-check"
disabled="{not recipeDetailBean.dirty}"
action="#{recipeDetailBean.doSave}"
/>
@ -359,6 +361,32 @@
/>
</h:form>
</p:panel>
<p:dialog id="addGroupDlg" widgetVar="addGroupDlg">
<h:form id="frmAddGroup">
<p:panelGrid columns="1">
<p:outputLabel for="@next"
value="Group Name"
/>
<p:inputText id="ctlNewGroupName"
value="#{recipeDetailBean.newGroupName}"
/>
<p:panelGrid columns="2"
style="width: 100%"
>
<p:commandButton id="agDlgOK"
value="OK" style="width: 6em"
action="#{recipeDetailBean.doAddGroup}"
update="form1:tabGroupClient:ingredientTable"
oncomplete="PF('addGroupDlg').hide()"
/>
<p:commandButton id="agDlgCan"
value="Cancel" style="width: 6em"
onclick="PF('addGroupDlg').hide()"
/>
</p:panelGrid>
</p:panelGrid>
</h:form>
</p:dialog>
<p:dialog id="editShopcatDlg"
widgetVar="editShopcatDlg"
>

View File

@ -9,80 +9,118 @@
<!-- Print Recipe -->
<ui:define name="title">Gourmet Recipe Manager</ui:define>
<ui:define name="content">
<h:messages />
<img id="bigpix"
SRC="/img/picture/#{recipeDetailBean.recipe.id}"
/>&nbsp;&nbsp;
<p:commandButton value="&lt;- Back" action="main.jsf" />
<p:panelGrid columns="2">
<h:outputLabel for="@next" value="Category: " />
<h:outputText
value="#{adminMainBean.formatCategories(recipeDetailBean.recipe)}"
/>
<h:outputLabel for="@next" value="Cuisine: " />
<h:outputText
value="#{recipeDetailBean.recipe.cuisine}"
/>
<h:outputLabel for="@next" value="Prep Time: " />
<h:outputText
value="#{userSession.formatTime(recipeDetailBean.recipe.preptime)}"
/>
<h:outputLabel for="@next" value="Cook Time: " />
<h:outputText label="Cook Time: "
value="#{userSession.formatTime(recipeDetailBean.recipe.cooktime)}"
/>
</p:panelGrid>
<!-- -->
<p:panelGrid columns="1" id="ingredientsc">
<f:facet name="header">
<h:outputText styleClass="subtitle"
value="Ingredients"
/>
</f:facet>
<p:dataTable id="ingredients"
showDirectLinksArrows="true"
value="#{recipeDetailBean.ingredients}"
var="ingredient"
<h:form id="printForm">
<h:messages />
<p:panelGrid
style="margin-bottom: 5px; border-style: none"
>
<p:column label="Amt" style="text-align: right">
<h:outputText
value="#{ingredient.displayAmount}"
<p:column>
<img id="bigpix"
SRC="/img/picture/#{recipeDetailBean.recipe.id}"
/>
</p:column>
<p:column label="Units">
<h:outputText value="#{ingredient.unit}" />
</p:column>
<p:column label="Item">
<h:outputText value="#{ingredient.item}" />
</p:column>
<p:column label="Optional" align="center">
<p:selectBooleanCheckbox readonly="true"
value="#{ingredient.optionalCB}"
<p:column
style="vertical-align: middle; text-align: left; border: none"
>
<p:commandButton value="&lt;- Back"
style="margin-left: 2em" immediate="true"
action="/main.jsf"
/>
</p:column>
</p:dataTable>
</p:panelGrid>
<h:outputText
value="Recipe ID: #{recipeDetailBean.recipe.id}"
/>
<p:panelGrid columns="1">
<f:facet name="header">
<h:outputText styleClass="subtitle"
value="Instructions"
</p:panelGrid>
<p:panelGrid columns="2">
<h:outputLabel for="@next" value="Category: " />
<h:outputText
value="#{userSession.formatCategories(recipeDetailBean.recipe)}"
/>
</f:facet>
<h:outputLabel for="@next" value="Cuisine: " />
<h:outputText
value="#{recipeDetailBean.recipe.cuisine}"
/>
<h:outputLabel for="@next" value="Prep Time: " />
<h:outputText
value="#{userSession.formatTime(recipeDetailBean.recipe.preptime)}"
/>
<h:outputLabel for="@next" value="Cook Time: " />
<h:outputText label="Cook Time: "
value="#{userSession.formatTime(recipeDetailBean.recipe.cooktime)}"
/>
</p:panelGrid>
<!-- -->
<h:outputText id="instructions" escape="false"
value="#{recipeDetailBean.instructions}"
<p:panelGrid id="ingredientsc">
<f:facet name="header">
<h:outputText styleClass="subtitle"
value="Ingredients"
/>
</f:facet>
<p:column style="padding: 0px 4px">
<p:dataTable id="ingredients"
showDirectLinksArrows="true"
value="#{recipeDetailBean.ingredients}"
var="ingredient"
>
<p:column
style="text-align: right; width: 2em"
>
<f:facet name="header">
Amt.
</f:facet>
<h:outputText
value="#{ingredient.displayAmount}"
/>
</p:column>
<p:column style="width: 6em">
<f:facet name="header">Units</f:facet>
<h:outputText
value="#{ingredient.unit}"
/>
</p:column>
<p:column>
<f:facet name="header">
Item
</f:facet>
<h:outputText
value="#{ingredient.item}"
/>
</p:column>
<p:column align="center"
style="width: 2em"
>
<f:facet name="header">
Opt.
</f:facet>
<p:selectBooleanCheckbox
readonly="true"
value="#{ingredient.optionalCB}"
/>
</p:column>
</p:dataTable>
</p:column>
</p:panelGrid>
<h:outputText
value="Recipe ID: #{recipeDetailBean.recipe.id}"
/>
</p:panelGrid>
<p:panelGrid columns="1">
<f:facet name="header">
<h:outputText styleClass="subtitle" value="Notes" />
</f:facet>
<h:outputText escape="false"
value="#{recipeDetailBean.modifications}"
/>
</p:panelGrid>
<p:panelGrid columns="1">
<f:facet name="header">
<h:outputText styleClass="subtitle"
value="Instructions"
/>
</f:facet>
<!-- -->
<h:outputText id="instructions" escape="false"
value="#{recipeDetailBean.instructions}"
/>
</p:panelGrid>
<p:panelGrid columns="1">
<f:facet name="header">
<h:outputText styleClass="subtitle"
value="Notes"
/>
</f:facet>
<h:outputText escape="false"
value="#{recipeDetailBean.modifications}"
/>
</p:panelGrid>
</h:form>
</ui:define>
</ui:composition>