Added suggestions for mainpage search

This commit is contained in:
Tim Holloway 2022-01-10 20:00:31 -05:00
parent d4d3179017
commit 8224c5eb31
2 changed files with 29 additions and 4 deletions

View File

@ -13,6 +13,7 @@ import javax.inject.Named;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.mousetech.gourmetj.persistence.model.Recipe; import com.mousetech.gourmetj.persistence.model.Recipe;
@ -95,6 +96,30 @@ public class AdminMainBean implements Serializable {
userSession.setLastSearch(searchText); userSession.setLastSearch(searchText);
} }
private List<String> suggestionList = null;
public void resetSuggestions() {
suggestionList = null;
}
public List<String> searchSuggestionList(String query) {
if (suggestionList == null) {
switch (this.userSession.getSearchType()) {
case rst_BY_CATEGORY:
suggestionList =
recipeService.findCategories();
break;
case rst_BY_CUISINE:
suggestionList =
recipeService.findCuisines();
break;
default:
suggestionList = new ArrayList<String>(1);
}
}
return suggestionList;
}
/**/ /**/
transient DataModel<Recipe> searchResults; transient DataModel<Recipe> searchResults;

View File

@ -10,15 +10,16 @@
<h:messages /> <h:messages />
<h:form id="form1"> <h:form id="form1">
<div> <div>
<p:inputText id="searchFor" size="45" <p:autoComplete id="searchFor" size="45"
placeholder="Recipe title/cuisine/category, etc.)" placeholder="Recipe title/cuisine/category, etc.)"
value="#{adminMainBean.searchText}" value="#{adminMainBean.searchText}"
completeMethod="#{adminMainBean.searchSuggestionList}"
> >
<f:ajax event="change" execute="@this" <f:ajax event="change" execute="@this"
render="form2:table1" render="form2:table1"
listener="#{adminMainBean.ajaxUpdateList}" listener="#{adminMainBean.ajaxUpdateList}"
/> />
</p:inputText> </p:autoComplete>
<p:defaultCommand target="find" /> <p:defaultCommand target="find" />
<p:commandButton id="find" value="Find" <p:commandButton id="find" value="Find"
icon="ui-icon-search" icon="ui-icon-search"
@ -28,12 +29,11 @@
<p:outputLabel for="@next" value="Search for " /> <p:outputLabel for="@next" value="Search for " />
<p:selectOneMenu id="ctlSearchType" <p:selectOneMenu id="ctlSearchType"
value="#{userSession.searchType}" value="#{userSession.searchType}"
immediate="true"
> >
<f:selectItems <f:selectItems
value="#{userSession.searchTypeList}" value="#{userSession.searchTypeList}"
/> />
<p:ajax /> <p:ajax listener="#{adminMainBean.resetSuggestions}"/>
</p:selectOneMenu> </p:selectOneMenu>
<p:commandButton id="ctlClear" value="Clear" <p:commandButton id="ctlClear" value="Clear"
icon="ui-icon-close" icon="ui-icon-close"