Wednesday, July 18, 2012

AutoSuggest For InputTextField

AutoSuggest is a very good feature in terms of LOV Below are the step to create AutoSuggest 1)Create a ViewObject (EmployeesVO) 2)For Department Attribute Define List Of Values - Note below items when you define this - You will have to define VO on Read Only access through SQL Query (You need this becasue in this query you need to have an attribute to hold department name for autosuggest to pull this value you need to create a query like below and make sure in Viewobject for each attribute you set the updateable property to Always) SELECT Emp.FirstName, Emp.LastName, Emp.DeptId, (SELECT Dept.DeptName FROM Department Dept WHERE Dept.DeptId = Emp.DeptId) DeptName FROM Employees Emp You autoSuggest will work on this attribute. 3)Define default viewobject for Departments table, this will be the lov for the attribute DeptNm in Employees. 4) In EmployeesVO select attribute DeptName and define lov, make sure when you select DepartmentVO in list datasource in your return value you should have two values something like ViewAttribute ListAttribute DeptName DepartmentName DeptId DepartmentId What will happen is when ever you whill select department name using autosuggest the corresponding value for deptid will be copied to DeptId column in EmployeeVO. 5) In UI Hints select InputText with List Of Values and diplay attribute set to Department Name 5) Now on you JSF page drag and drop EmployeesVO as table for the DepartmentName attribute copy below line before the closing column tag af:autoSuggestBehavior suggestedItems="#{row.bindings.DeptName.suggestedItems}"/ No need to add any list in page definition it will automatically pick up from the LOV defined in the viewobject.