Moved search time to application scope

version2
tim holloway 3 months ago
parent 9cf0f89e76
commit 61942f547a
  1. 51
      src/main/java/com/mousetech/gourmetj/AppBean.java
  2. 26
      src/main/java/com/mousetech/gourmetj/UserSession.java
  3. 4
      src/main/resources/META-INF/resources/main.xhtml

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

@ -129,32 +129,6 @@ public class UserSession implements Serializable {
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) {

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

Loading…
Cancel
Save