Tag Archives: list

af:autosuggestBehavior – intro

This component in adf is used to provide a declarative way of providing suggestions for adf input components
the three main attributes are
suggestItems – mapped to a bean which returns List of SelectItems.
maxSuggestedItems – number of suggestedItems. -1 will fetch everything from the server. if the number is limited then a more link is displayed to fetch remaining items from the server
smartList – this list is added to show intial result. then the entire result from the server is fetched if no operation is done by the user

problem: I have a destination inputText which takes city/state combination. I want to implement an autosuggestbehavior for the inputText. When I enter more than three character the suggestion box should appear which City/States.

1) create an af:inputText, the value of the inputText is mapped to a managedBean to store the value that is entered by the user

<af:inputText label="Destination" id="end"
contentStyle="width: 133px;margin-left:5px;"

//managedbean code
private String dest;
public void setDest(String dest) {
this.dest = dest;

public String getDest() {
return dest;

2) now add an af:autosuggestbehavior tag to the inputText. This takes two attribute values. suggestItems and maxSuggestItems. provide maxSuggestItems as ‘5’ to display 5 values. suggestItems is bounded to the managedbean with a method ‘destination’ which returns a List of SelectItems.

<af:inputText label="Destination" id="end"
<af:autoSuggestBehavior suggestItems="#{mapBean.destination}"

public List destination(FacesContext facesContext,
AutoSuggestUIHints autoSuggestUIHints) {
//create suggestion list
List<SelectItem> items = new ArrayList<SelectItem>();
// the list should activate after three character
if(autoSuggestUIHints.getSubmittedValue().length() >= 3){
//get the binding from the pagedef
DCIteratorBinding bindings = getIteratorBinding("CityStateIterator");

OperationBinding operation = null;
String value = autoSuggestUIHints.getSubmittedValue();

//executing the operation binding that will execute a viewcrtieria from ViewImpl
operation = bindings.getBindingContainer().getOperationBinding("searchByCityState");
//bind variable for city and state
String city = value.substring(0, value.indexOf(","));
String state = value.substring(value.indexOf(","), value.length());
operation.getParamsMap().put("city", city);
operation.getParamsMap().put("state", state.replace(", ", ""));
//execute the view criteria

if (operation.getResult() != null) {
RowSet result = (RowSet) operation.getResult(); // cast to the expected result type
//the result is stored in the list
items = populateSuggestionList(items, result);
//show suggestions
return items;
//populate the values in a List of SelectItems
private List<SelectItem> populateSuggestionList(List<SelectItem> items,
RowSet vo) {
//populate the suggestion items
RowSet rs = vo.getRowSet();
while (rs.hasNext()) {
Row rw = rs.next();
items.add(new SelectItem(rw.getAttribute("CITY").toString().trim() + ", " + rw.getAttribute("STATE").toString().trim(),
((String)rw.getAttribute("CITY")).trim() + ", " +

return items;


to learn more you can refer these links

af:selectonechoice not getting updated

Today i had an interesting problem at work. The issue is that the user selects the value from a selectonechoice and moves to the next page and when he returns back to the same old page the selectonechoice is not updated with the value that is selected previously.

the selectonechoice is not bounded to any of the bindings and we manually create the list using the managed bean. here is the base snippet which resembles the problem

selectOneChoice simple="true" value="#{Bean.list.itemNo}" id="soc1" unselectedLabel="Please Select">
 selectItems value="#{Bean.listItems}"/>

while debugging the value the value is all available but somehow the value is not shown in the selectonechoice. The value is again moves to the “Please Select” option specified in the unselectedLabel when the user moves back to the original page.

couple of things i tried which failed
1)binding to the bean and getting the value

2) having the value as “#{Bean.list[‘itemNo’]}”

finally I got to see the following warning in the log saying

13-Jul-2011 20:27:54 oracle.adfinternal.view.faces.renderkit.core.xhtml.SimpleSelectOneRenderer _getSelectedIndex
WARNING: Could not find selected item matching value "1" in CoreSelectOneChoice[UIXEditableFacesBeanImpl, id=soc1]

This warning gave me a hint to think the problem in a different way and leads to the solution

Actually the list that we are manipulating assigns the value on the fly like


List<SelectItem> items = new Arraylist();


//inside the method

items.add(new SelectItem(code.getItemlabel(), code.getItemValue()));


the above code has to rewritten as shown to solve the above mentioned issue

//inside the method

SelectItem item = new SelectIem();


item.setValue(code.getItemValue()); //here the value should be an Integer value
//if the value is a String then this has to be like