Moved search time to application scope

This commit is contained in:
tim holloway 2024-02-01 15:52:07 -05:00
parent 9cf0f89e76
commit 61942f547a
3 changed files with 53 additions and 28 deletions

View File

@ -0,0 +1,51 @@
package com.mousetech.gourmetj;
import java.util.ArrayList;
import java.util.List;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.faces.model.SelectItem;
import jakarta.inject.Named;
/**
* Appplication-scope data (mostly constants)
*
* @author timh
* @since Feb 1, 2024
*/
@Named
@ApplicationScoped
public class AppBean {
public AppBean() {
// TODO Auto-generated constructor stub
}
private List<SelectItem> searchTypeList;
/**
* @return the searchTypeList
* @see RecipeSearchType
* Used by main.xhtml
*/
public List<SelectItem> getSearchTypeList() {
if (searchTypeList == null) {
searchTypeList = loadSearchTypeList();
}
return searchTypeList;
}
private List<SelectItem> loadSearchTypeList() {
List<SelectItem> list = new ArrayList<SelectItem>(5);
list.add(new SelectItem(RecipeSearchType.rst_BY_NAME.ordinal(),
"Title"));
list.add(new SelectItem(RecipeSearchType.rst_BY_CATEGORY.ordinal(),
"Category"));
list.add(new SelectItem(RecipeSearchType.rst_BY_CUISINE.ordinal(),
"Cuisine"));
list.add(
new SelectItem(RecipeSearchType.rst_BY_INGREDIENT.ordinal(),
"Ingredient"));
return list;
}
}

View File

@ -129,32 +129,6 @@ public class UserSession implements Serializable {
this.searchType = searchType; this.searchType = searchType;
} }
private List<SelectItem> searchTypeList;
/**
* @return the searchTypeList
*/
public List<SelectItem> getSearchTypeList() {
if (searchTypeList == null) {
searchTypeList = loadSearchTypeList();
}
return searchTypeList;
}
private List<SelectItem> loadSearchTypeList() {
List<SelectItem> list = new ArrayList<SelectItem>(5);
list.add(new SelectItem(RecipeSearchType.rst_BY_NAME.ordinal(),
"Title"));
list.add(new SelectItem(RecipeSearchType.rst_BY_CATEGORY.ordinal(),
"Category"));
list.add(new SelectItem(RecipeSearchType.rst_BY_CUISINE.ordinal(),
"Cuisine"));
list.add(
new SelectItem(RecipeSearchType.rst_BY_INGREDIENT.ordinal(),
"Ingredient"));
return list;
}
// ==== // ====
public String formatCategories(Recipe r) { public String formatCategories(Recipe r) {

View File

@ -31,7 +31,7 @@
value="#{cookieBean.searchType}" value="#{cookieBean.searchType}"
> >
<f:selectItems <f:selectItems
value="#{userSession.searchTypeList}" value="#{appBean.searchTypeList}"
/> />
<p:ajax <p:ajax
listener="#{adminMainBean.resetSuggestions}" listener="#{adminMainBean.resetSuggestions}"
@ -45,7 +45,7 @@
<p:commandButton value="New Recipe" <p:commandButton value="New Recipe"
action="#{adminMainBean.doNewRecipe}" action="#{adminMainBean.doNewRecipe}"
/> />
<p:commandButton value="More..." <p:commandButton value="Shopping..."
action="#{adminMainBean.doMore}" action="#{adminMainBean.doMore}"
/> />
<h:outputText id="slistSSize" <h:outputText id="slistSSize"