When using the RichFaces suggestionBox
how can you pass more than one id or value from the page with the text input to the suggestionBox
backing be
You can use the rich:suggestionbox
. My task was filtering a list according to some attribute of the list element, where sometimes that attribute could be ignored. Like, sometimes I want a list of only citrus fruit, and sometimes I want the entire list of available fruit.
In the page:
...
I had one class (Basket
) that knew if the list had to be special-filtered, and another class (ListBuilder
) that built the list.
In Basket
:
public Boolean getIsConstrainedToCitrus ()
{
return new Boolean ( logic that answers "is this basket for citrus only" );
}
In ListBuilder:
public List autocompleteFilterFruit (Object arg)
{
List rtnList = new ArrayList ();
String suggestion = (String) arg;
// get the filter control that the page retrieved from the Basket
//
Map params = FacesContext.getCurrentInstance().getExternalContext ().getRequestParameterMap();
boolean isConstrainedToCitrus = "true".equals (params.get ("constrainInd"));
// allFruit is a pre-initialized list of all the available fruit. use it to populate the return list according
// to the filter rules and matches to the auto-complete suggestions
for (Fruit item : allFruit)
{
if ((!isConstrainedToCitrus || item.isCitrus()) && item.name.startsWith(suggestion))
{
rtnList.add (item);
}
}
return rtnList;
}