1 5 package org.exoplatform.faces.search.component; 6 7 import java.util.*; 8 import org.exoplatform.faces.core.component.*; 9 import org.exoplatform.faces.core.component.model.*; 10 import org.exoplatform.faces.core.event.ExoActionEvent; 11 import org.exoplatform.faces.core.event.ExoActionListener; 12 17 public class UISearchBar extends UISimpleForm { 18 static final public String SEARCH_ACTION = "search" ; 19 static final public String ADVANCED_SEARCH_ACTION = "advancedSearch" ; 20 21 private UIStringInput termInput_ ; 22 private UISelectBox searchFieldInput_; 23 private List searchOptions_ ; 24 25 public UISearchBar() { 26 super("quickSearchForm", "post", null) ; 27 setId("UISearchBar") ; 28 setClazz("UISearchBar"); 29 30 termInput_ = new UIStringInput("term", "") ; 31 searchFieldInput_= new UISelectBox("searchField", "", null ); 32 add(new Row(). 33 add(new ListComponentCell(). 34 add(this, termInput_ ). 35 add(this, searchFieldInput_ ). 36 add(new FormButton("#{UISearchBar.button.search}", SEARCH_ACTION))). 37 add(new ListComponentCell(). 38 add(new FormButton("#{UISearchBar.button.advanced-search}", ADVANCED_SEARCH_ACTION)). 39 addAlign("right"))) ; 40 41 addActionListener(AdvancedSearchActionListener.class, ADVANCED_SEARCH_ACTION) ; 42 addActionListener(SearchActionListener.class, SEARCH_ACTION) ; 43 } 44 45 public boolean isRendered() { return true ; } 46 47 public void setSearchOptions(List options) { 48 searchOptions_ = options ; 49 searchFieldInput_.setOptions(options) ; 50 } 51 52 static public class SearchActionListener extends ExoActionListener { 53 public void execute(ExoActionEvent event) throws Exception { 54 UISearchBar uiForm = (UISearchBar) event.getSource(); 55 String term = uiForm.termInput_.getValue() ; 56 if(term == null || term.length() == 0) return ; 57 String select = uiForm.searchFieldInput_.getValue() ; 58 List fields = new ArrayList() ; 59 if("".equals(select)) { 60 for(int i = 0; i < uiForm.searchOptions_.size(); i++) { 61 SelectItem item = (SelectItem) uiForm.searchOptions_.get(i) ; 62 if(item.value_.length() > 0) { 63 fields.add(item.value_) ; 64 } 65 } 66 } else { 67 fields.add(select) ; 68 } 69 UISearcher uiSearcher = (UISearcher) uiForm.getParent() ; 70 uiSearcher.quickSearch(term, fields) ; 71 } 72 } 73 74 static public class AdvancedSearchActionListener extends ExoActionListener { 75 public void execute(ExoActionEvent event) throws Exception { 76 UISearchBar uiSearch = (UISearchBar) event.getSource(); 77 UISearcher uiSearcher = (UISearcher) uiSearch.getParent() ; 78 uiSearcher.showAdvancedSearch() ; 79 } 80 } 81 } | Popular Tags |