Sunday, November 1, 2009

Filling SelectOneChoice From Backingbean

On of the major component in tha ADF RC component is a af:selectOneChoice. You can fill this component from backingbean by tow ways:

A) Fill SelectOneChoice Component Programmatically:
1-In the backingbean you can define a variable that hold the selected Value (the value which you are select from selectOneChoice component ) [e.g public String selectedValue;] and make its setter and getter.
2- In the backingbean you can define an array of selectItem that will fill the selectOneChoice(e.g. public SelectItem[] elements = null; ) and make its getter and setter.
3- In the getter of selectItem write this code :



where : UCustomerView1Iterator is the Iterator which its data will fill the selectOneChoice (You must add this iterator in the pageDef).

You backingbean it should be like this :
-----------------------------------------------



4- In you page Drage a selectOneChoice component and set its value to :
#{yourBean.selectedValue}.
5- Insert f:selectItems inside af:selectOneChoice and set its value to:
#{yourBean.elements}.
--------------------------------------------------------------------------------
B) The second method to fill the selectOneChioce is to use af:forEach component and I prefer this method :
1- In the pageDef make a table in the binding section that will fill your selectOneChoice(assume that you make a DeptView1 table in the binding.
2- DeptView1 Table is point to the DeptView1Iterator make its length to -1.
3- Drag and drop a selectOneChoice component and set its value to the attribute in the backingbean.
4- Insert inside selectOneChoice af:forEach component and set Items property to : #{bindings.DeptView1.rangeSet} and set Var property to row.
5- Insert Inside af:forEach af:selectItem set Value Property to #{row.Deptno} this represent the return value of the selectOneChoice if you want the return value be a name of the department set Value Property to #{row.Dname}. Set the Label Property to #{row.Dname}.(Where Deptno and Dname is the attribute of the iterator you use to fill selectOneChoice).
you can download an example from here.

2 comments: