Implement AutoSuggestion behavior in ADF
Hi All,
In this post I am going to show you how you can implement AutoSuggestion behavior in ADF.
In this example I have taken the example of EmployeesVO which is based on EMPLOYEES table of HR schema.
Suppose you have one DepatrmentId attribute in you view object EmployeesVO and you have dragged and dropped it on to your page as input text. as shown below.
In you code it will look like this
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<f:view>
<af:document id="d1">
<af:messages id="m1"/>
<af:form id="f1">
<af:inputText value="#{bindings.DepartmentId.inputValue}"
label="#{bindings.DepartmentId.hints.label}"
required="#{bindings.DepartmentId.hints.mandatory}"
columns="#{bindings.DepartmentId.hints.displayWidth}"
maximumLength="#{bindings.DepartmentId.hints.precision}"
shortDesc="#{bindings.DepartmentId.hints.tooltip}"
id="it2">
<f:validator binding="#{bindings.DepartmentId.validator}"/>
<af:convertNumber groupingUsed="false"
pattern="#{bindings.DepartmentId.format}"/>
</af:inputText>
</af:form>
</af:document>
</f:view>
</jsp:root>
Now drag and drop the Auto Suggestion Behavior operation from you component palette inside the input text component. Then bind the suggestedItems property to you bean as follows:
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<f:view>
<af:document id="d1">
<af:messages id="m1"/>
<af:form id="f1">
<af:inputText value="#{bindings.DepartmentId.inputValue}"
label="#{bindings.DepartmentId.hints.label}"
required="#{bindings.DepartmentId.hints.mandatory}"
columns="#{bindings.DepartmentId.hints.displayWidth}"
maximumLength="#{bindings.DepartmentId.hints.precision}"
shortDesc="#{bindings.DepartmentId.hints.tooltip}"
id="it2">
<f:validator binding="#{bindings.DepartmentId.validator}"/>
<af:convertNumber groupingUsed="false"
pattern="#{bindings.DepartmentId.format}"/>
<af:autoSuggestBehavior maxSuggestedItems="25"
suggestedItems="#{backingBeanScope.TestBean.getSuggestedItems}"/>
</af:inputText>
</af:form>
</af:document>
</f:view>
</jsp:root>
In your bean you will have following method:
import java.util.ArrayList;
import java.util.List;
import javax.faces.model.SelectItem;
import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.model.binding.DCIteratorBinding;
import oracle.jbo.Row;
import oracle.jbo.RowSetIterator;
import oracle.jbo.ViewCriteria;
import oracle.jbo.ViewCriteriaRow;
import oracle.jbo.ViewObject;
public class TestBean {
public TestBean() {
}
public List getSuggestedItems(String string) {
ArrayList<SelectItem> selectItems = new ArrayList<SelectItem>();
DCBindingContainer dcBindings =
(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding iterBind =
(DCIteratorBinding)dcBindings.get("EmployeesVO1Iterator");
ViewObject vo = iterBind.getViewObject();
ViewCriteria vc = vo.createViewCriteria();
ViewCriteriaRow criteriaRow = vc.createViewCriteriaRow();
criteriaRow.setAttribute("DepartmentId", string);
vc.addElement(criteriaRow);
vo.applyViewCriteria(vc, true);
vo.executeQuery();
RowSetIterator rs = vo.createRowSetIterator(null);
rs.reset();
while (rs.hasNext()) {
Row row = rs.next();
Object i =
((oracle.jbo.domain.Number)row.getAttribute("DepartmentId")).intValue();
String desc = (String)row.getAttribute("FirstName");
selectItems.add(new SelectItem(i + "-" + desc, i + "-" + desc));
}
return selectItems;
}
}
Now run your page and see that Auto suggestion is perfectly working as expected as shown below:
Happy Coding :)
In this post I am going to show you how you can implement AutoSuggestion behavior in ADF.
In this example I have taken the example of EmployeesVO which is based on EMPLOYEES table of HR schema.
Suppose you have one DepatrmentId attribute in you view object EmployeesVO and you have dragged and dropped it on to your page as input text. as shown below.
In you code it will look like this
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<f:view>
<af:document id="d1">
<af:messages id="m1"/>
<af:form id="f1">
<af:inputText value="#{bindings.DepartmentId.inputValue}"
label="#{bindings.DepartmentId.hints.label}"
required="#{bindings.DepartmentId.hints.mandatory}"
columns="#{bindings.DepartmentId.hints.displayWidth}"
maximumLength="#{bindings.DepartmentId.hints.precision}"
shortDesc="#{bindings.DepartmentId.hints.tooltip}"
id="it2">
<f:validator binding="#{bindings.DepartmentId.validator}"/>
<af:convertNumber groupingUsed="false"
pattern="#{bindings.DepartmentId.format}"/>
</af:inputText>
</af:form>
</af:document>
</f:view>
</jsp:root>
Now drag and drop the Auto Suggestion Behavior operation from you component palette inside the input text component. Then bind the suggestedItems property to you bean as follows:
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<f:view>
<af:document id="d1">
<af:messages id="m1"/>
<af:form id="f1">
<af:inputText value="#{bindings.DepartmentId.inputValue}"
label="#{bindings.DepartmentId.hints.label}"
required="#{bindings.DepartmentId.hints.mandatory}"
columns="#{bindings.DepartmentId.hints.displayWidth}"
maximumLength="#{bindings.DepartmentId.hints.precision}"
shortDesc="#{bindings.DepartmentId.hints.tooltip}"
id="it2">
<f:validator binding="#{bindings.DepartmentId.validator}"/>
<af:convertNumber groupingUsed="false"
pattern="#{bindings.DepartmentId.format}"/>
<af:autoSuggestBehavior maxSuggestedItems="25"
suggestedItems="#{backingBeanScope.TestBean.getSuggestedItems}"/>
</af:inputText>
</af:form>
</af:document>
</f:view>
</jsp:root>
In your bean you will have following method:
import java.util.ArrayList;
import java.util.List;
import javax.faces.model.SelectItem;
import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.model.binding.DCIteratorBinding;
import oracle.jbo.Row;
import oracle.jbo.RowSetIterator;
import oracle.jbo.ViewCriteria;
import oracle.jbo.ViewCriteriaRow;
import oracle.jbo.ViewObject;
public class TestBean {
public TestBean() {
}
public List getSuggestedItems(String string) {
ArrayList<SelectItem> selectItems = new ArrayList<SelectItem>();
DCBindingContainer dcBindings =
(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding iterBind =
(DCIteratorBinding)dcBindings.get("EmployeesVO1Iterator");
ViewObject vo = iterBind.getViewObject();
ViewCriteria vc = vo.createViewCriteria();
ViewCriteriaRow criteriaRow = vc.createViewCriteriaRow();
criteriaRow.setAttribute("DepartmentId", string);
vc.addElement(criteriaRow);
vo.applyViewCriteria(vc, true);
vo.executeQuery();
RowSetIterator rs = vo.createRowSetIterator(null);
rs.reset();
while (rs.hasNext()) {
Row row = rs.next();
Object i =
((oracle.jbo.domain.Number)row.getAttribute("DepartmentId")).intValue();
String desc = (String)row.getAttribute("FirstName");
selectItems.add(new SelectItem(i + "-" + desc, i + "-" + desc));
}
return selectItems;
}
}
Now run your page and see that Auto suggestion is perfectly working as expected as shown below:
Happy Coding :)
Comments
Post a Comment