Handle null in 'optional' Ingredient field
This commit is contained in:
parent
5ef369743a
commit
e5984e5d6f
|
@ -1,6 +1,5 @@
|
|||
package com.mousetech.gourmetj;
|
||||
|
||||
|
||||
import com.mousetech.gourmetj.persistence.model.Ingredient;
|
||||
import com.mousetech.gourmetj.persistence.model.IngredientIF;
|
||||
import com.mousetech.gourmetj.persistence.model.Recipe;
|
||||
|
@ -9,8 +8,8 @@ import com.mousetech.gourmetj.IngredientDigester.IngredientAmountFormat;
|
|||
|
||||
/**
|
||||
* JSF-friendly decorator for @see Ingredient. Formats amount
|
||||
* with fractions and supports checkboxes. Primary use
|
||||
* is as a JSF TableModel wrapped content in @see RecipeDetailBean.
|
||||
* with fractions and supports checkboxes. Primary use is as a
|
||||
* JSF TableModel wrapped content in @see RecipeDetailBean.
|
||||
*
|
||||
* TestedBy @see IngredientUITest
|
||||
*
|
||||
|
@ -22,6 +21,7 @@ public class IngredientUI implements IngredientIF {
|
|||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param ingredient
|
||||
*/
|
||||
public IngredientUI(Ingredient ingredient) {
|
||||
|
@ -33,6 +33,7 @@ public class IngredientUI implements IngredientIF {
|
|||
}
|
||||
|
||||
private boolean ingGroup;
|
||||
|
||||
/**
|
||||
* @param ingGroup the ingGroup to set
|
||||
*/
|
||||
|
@ -41,13 +42,13 @@ public class IngredientUI implements IngredientIF {
|
|||
}
|
||||
|
||||
/**
|
||||
* Ingredient groups are rendered visually as synthetic
|
||||
* rows. Actual group IDs are part of line-item ingredients,
|
||||
* so when building the model, we create a group row when
|
||||
* the line item inggroup value changes.
|
||||
* Ingredient groups are rendered visually as synthetic rows.
|
||||
* Actual group IDs are part of line-item ingredients, so
|
||||
* when building the model, we create a group row when the
|
||||
* line item inggroup value changes.
|
||||
*
|
||||
* @return <code>true</code> for an Ingredient Group
|
||||
* header row.
|
||||
* @return <code>true</code> for an Ingredient Group header
|
||||
* row.
|
||||
*/
|
||||
public boolean isIngGroup() {
|
||||
return this.ingGroup;
|
||||
|
@ -59,7 +60,6 @@ public class IngredientUI implements IngredientIF {
|
|||
|
||||
private boolean selected;
|
||||
|
||||
|
||||
/**
|
||||
* @return the selected status
|
||||
*/
|
||||
|
@ -74,7 +74,6 @@ public class IngredientUI implements IngredientIF {
|
|||
this.selected = selected;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @see com.mousetech.gourmetj.persistence.model.Ingredient#getAmount()
|
||||
|
@ -93,6 +92,7 @@ public class IngredientUI implements IngredientIF {
|
|||
|
||||
/**
|
||||
* Get amount display-friendly
|
||||
*
|
||||
* @see #getAmount
|
||||
*/
|
||||
public String getDisplayAmount() {
|
||||
|
@ -102,12 +102,14 @@ public class IngredientUI implements IngredientIF {
|
|||
return "";
|
||||
}
|
||||
String amt1 = IngredientDigester.displayAmount(
|
||||
IngredientAmountFormat.IA_SYMBOLS, amt, ingredient.getRangeamount());
|
||||
IngredientAmountFormat.IA_SYMBOLS, amt,
|
||||
ingredient.getRangeamount());
|
||||
return amt1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set amount display-friendly
|
||||
*
|
||||
* @see #setAmount
|
||||
*/
|
||||
public void setDisplayAmount(String amount) {
|
||||
|
@ -119,6 +121,7 @@ public class IngredientUI implements IngredientIF {
|
|||
ingredient.setAmount(amt[0]);
|
||||
ingredient.setRangeamount(amt[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @see com.mousetech.gourmetj.persistence.model.Ingredient#getDeleted()
|
||||
|
@ -225,10 +228,15 @@ public class IngredientUI implements IngredientIF {
|
|||
|
||||
/**
|
||||
* Get optional value in boolean Checkbox friendly form
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean getOptionalCB() {
|
||||
return ingredient.getOptional() != 0;
|
||||
Integer optional = ingredient.getOptional();
|
||||
if (optional == null) {
|
||||
return false;
|
||||
}
|
||||
return optional != 0;
|
||||
}
|
||||
|
||||
public void setOptionalCB(boolean value) {
|
||||
|
@ -347,8 +355,8 @@ public class IngredientUI implements IngredientIF {
|
|||
ingredient.setUnit(unit);
|
||||
}
|
||||
|
||||
|
||||
// This goes to the shopCats table via ManyToOne at save time.
|
||||
// This goes to the shopCats table via ManyToOne at save
|
||||
// time.
|
||||
private String shopCat;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user