The problem
When you have an LOV (drop down, radio button group etc.) on the page and you want to get the code or String value of the currently selected item(s) in the backing bean; But calling the getValue() on the component returns the index of the item and not its code or value.The solution
Create the list items using a for loop around an <f:selectItem> instead of using an <af:selectItems>Dragging and dropping the VO for the LOV from the data control palette to the page creates the list binding for the LOV in the page definition and sets up the LOV for use. The default behavior of the list binding is to use the <af:selectItems> for the selectable LOV elements, which uses indexes rather than the actual values. So to use the actual values, we circumvent the default behavior my setting up the binding ourselves using a for… loop around an <f:selectItem> which lets us control both itemLabel and itemValue as opposed to the <af:selectItems> which does not offer such fine grained control. To do this, instead of dragging the VO to the page, use the component palette to select the LOV type you need (single/multi select list/dropdown) and then manually set the EL to get the individual items. The key here is to avoid using the list binding that JDeveloper creates for you and then use a for loop to create the selectable items in the list with finer control. On the page definition file, create a List binding for the VO you need, in this example, it’s the departmentsVO. From the page, you can iterate through the elements of this VO like below
<af:selectOneChoice label="#{bindings.DepartmentLOV.label}" id="textSingle" binding="#{pageFlowScope.LOVValueDemoBean.textLOVSingle}"> <af:forEach items="#{bindings.DepartmentLOV.iteratorBinding.allRowsInRange}" var="row"> <f:selectItem id="myItem2" itemLabel="#{row.departmentName}" itemValue="#{row.departmentName}"/> </af:forEach> </af:selectOneChoice>
Note the use of the <af:forEach> tag. We are not using the JSTL core taglib here, and the items attribute has the EL expression #{bindings.DepartmentLOV.iteratorBinding.allRowsInRange} This EL gives the items in the LOV in a format that’s usable by the <af:forEach> tag. Inside the loop is an <f:selectItem> tag with its label and value set to the values we’d like to see. The itemLabel is displayed on screen, and calling getValue() in the component will return the itemValue. The variable row, of course will be an instance of the DepartmentLOVRowImpl (in this example), so its properties can be accessed with EL as above.
The implementation is slightly different for single/multi select LOVs and what the itemValue is set to, depending on if you want to get the textual value that’s displayed or an LOV code (e.g. get dept no. when choosing the dept name) or some other property in the VO. Note that this works only if you have your VO's VORowImpl class generated/implemented.
Single select LOV
I want to get the string value of the text selected on screen
The following code goes to the page :
<af:selectOneChoice label="#{bindings.DepartmentLOV.label}" id="textSingle" binding="#{pageFlowScope.LOVValueDemoBean.textLOVSingle}"> <af:forEach items="#{bindings.DepartmentLOV.iteratorBinding.allRowsInRange}" var="row"> <f:selectItem id="myItem2" itemLabel="#{row.departmentName}" itemValue="#{row.departmentName}"/> </af:forEach> </af:selectOneChoice>
The backing bean method that is fired (can be bound with a valueChangeListener or as in the example, with a command button's action binding, which is not show below but is in the downloadable project code ):
public String getTextValueSingle() { String value = String.valueOf(getTextLOVSingle().getValue()); getValueDisplay().setValue(value); return null; }
I want to get the LOV code and not the displayed text
This goes to the page. Notice the <f:selectItem>'s itemValue and itemLabel :
<af:selectOneChoice label="#{bindings.DepartmentLOV.hints.label}" id="soc3" binding="#{pageFlowScope.LOVValueDemoBean.textIDLOV}"> <af:forEach items="#{bindings.DepartmentLOV.iteratorBinding.allRowsInRange}" var="row"> <f:selectItem id="myItem3" itemLabel="#{row.departmentName}" itemValue="#{row.departmentId}"/> </af:forEach> </af:selectOneChoice>The code for the backing bean is the same :
public String getTextIDValue() { String value = String.valueOf(getTextIDLOV().getValue()); getValueDisplay().setValue(value); return null; }
Multi select LOV
I want the display text values
The code for the page is the same expect for the change in the component used(its a multi select LOV)
<af:selectManyChoice label="Label 1" id="smc1" binding="#{pageFlowScope.LOVValueDemoBean.textMultiLOV}"> <af:forEach items="#{bindings.DepartmentLOV.iteratorBinding.allRowsInRange}" var="row"> <f:selectItem id="myItem4" itemLabel="#{row.departmentName}" itemValue="#{row.departmentName}"/> </af:forEach> </af:selectManyChoice>
The backing bean code is different here, because the multiselect LOV components return a list of Strings in return to the call to getValue(), as shown below :
public String getTextValueMulti() { List<String> selected = (List<String>) getTextMultiLOV().getValue(); String csvValue = ""; for (String s: selected) // For the example, we're displaying the strings as a comm separated list { csvValue = csvValue + s + ","; } getValueDisplay().setValue(csvValue); return null; }
I want to see the LOV codes
The page code, just like the single select example, the <f:selectItem>'s itemValue and itemLabel determine whats displayed on screen and what you get back from a call to getValue()
<af:selectManyChoice label="Label 2" id="smc2" binding="#{pageFlowScope.LOVValueDemoBean.textIDMultiLOV}"> <af:forEach items="#{bindings.DepartmentLOV.iteratorBinding.allRowsInRange}" var="row"> <f:selectItem id="myItem5" itemLabel="#{row.departmentName}" itemValue="#{row.departmentId}"/> </af:forEach> </af:selectManyChoice>The backing bean code, same as above, except that the list you get back is a list of oracle.jbo.domain.Number, the same type from the VOImpl.
public String getAllIDsSelected() { List<oracle.jbo.domain.Number> selected = // IDs are numbers, the type from the VO is preserved. (List<oracle.jbo.domain.Number>) getTextIDMultiLOV().getValue(); String csvValue = ""; for (oracle.jbo.domain.Number s: selected) { csvValue = csvValue + s.intValue() + ","; } getValueDisplay().setValue(csvValue); return null; }The example application can be downloaded here : LOV_example
hi,
ReplyDeletei tried to do the same cerated vo and expose the rowImpl class but i get error that
javax.el.PropertyNotFoundException: The class 'mps.model.gate.MpsVendorNameVORowImpl' does not have the property 'MpsVendorId'.
i compared with your application everything is same in the rowImpl.
Try giving the property name as mpsVendorId instead of MpsVendorId
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteWhat should I take for 'DepartmentLOV'?
ReplyDeletenice post, thanks
ReplyDeleteThis is a very good documentation. It would be great if you could give more details on the design by attaching some screenshots
ReplyDeleteIsparta
ReplyDeleteTunceli
Yozgat
Çorum
Konya
C7DMO
Bayburt
ReplyDeleteKars
Batman
Urfa
İzmir
3MN3
Burdur
ReplyDeleteGiresun
Sakarya
Artvin
Mardin
CAİE
Bursa
ReplyDeleteKırşehir
Muş
Mersin
Çanakkale
LZK2
Muğla
ReplyDeleteBitlis
Karaman
DGE1HJ
Afyon
ReplyDeleteBalıkesir
Kırklareli
Amasya
Bilecik
GHVR0R
Samsun
ReplyDeleteNevşehir
Van
Bartın
Edirne
ED1V
İstanbul
ReplyDeleteSivas
Kırıkkale
Zonguldak
Iğdır
Q6L
Aksaray
ReplyDeleteAydın
Kütahya
Rize
Bingöl
R2TZ8
Ankara
ReplyDeleteAntalya
istanbul
Ordu
izmir
7RYM
bitlis
ReplyDeleteurfa
mardin
tokat
çorum
U4JFQ
adana evden eve nakliyat
ReplyDeletebolu evden eve nakliyat
diyarbakır evden eve nakliyat
sinop evden eve nakliyat
kilis evden eve nakliyat
DF00L
aydın evden eve nakliyat
ReplyDeletebursa evden eve nakliyat
trabzon evden eve nakliyat
bilecik evden eve nakliyat
antep evden eve nakliyat
QC4H
maraş evden eve nakliyat
ReplyDeletemaraş evden eve nakliyat
izmir evden eve nakliyat
konya evden eve nakliyat
erzurum evden eve nakliyat
MGFL
düzce evden eve nakliyat
ReplyDeletedenizli evden eve nakliyat
kırşehir evden eve nakliyat
çorum evden eve nakliyat
afyon evden eve nakliyat
8UMB1
8D339
ReplyDeleteİstanbul Evden Eve Nakliyat
Etimesgut Parke Ustası
Çerkezköy Oto Elektrik
Balıkesir Evden Eve Nakliyat
Sinop Lojistik
Ünye Çekici
Rize Şehir İçi Nakliyat
Kırklareli Şehirler Arası Nakliyat
İzmir Şehir İçi Nakliyat
A53CD
ReplyDeleteAntep Parça Eşya Taşıma
Pancakeswap Güvenilir mi
Yozgat Parça Eşya Taşıma
Ordu Lojistik
Ankara Evden Eve Nakliyat
Yozgat Lojistik
Çerkezköy Oto Elektrik
Nevşehir Parça Eşya Taşıma
Konya Parça Eşya Taşıma
B3176
ReplyDeleteHamster Coin Hangi Borsada
Osmaniye Evden Eve Nakliyat
Bingöl Şehirler Arası Nakliyat
İzmir Parça Eşya Taşıma
Bursa Şehir İçi Nakliyat
Hakkari Lojistik
Altındağ Parke Ustası
Pursaklar Fayans Ustası
Referans Kimliği Nedir
68366
ReplyDeleteMalatya Evden Eve Nakliyat
Mercatox Güvenilir mi
Edirne Evden Eve Nakliyat
Iğdır Evden Eve Nakliyat
Amasya Evden Eve Nakliyat
Yozgat Evden Eve Nakliyat
Ünye Oto Lastik
Tekirdağ Çatı Ustası
Ünye Oto Elektrik
DA334
ReplyDeleteresimlimag.net
F920C
ReplyDeleteresimli magnet
binance referans kodu
resimli magnet
resimli magnet
referans kimliği nedir
binance referans kodu
binance referans kodu
binance referans kodu
referans kimliği nedir
AC04C
ReplyDeletesightcare
EF203
ReplyDeletebartın görüntülü sohbet uygulama
Gümüşhane Mobil Sesli Sohbet
Hatay En İyi Ücretsiz Sohbet Uygulamaları
malatya canlı sohbet et
bursa rastgele canlı sohbet
çankırı ücretsiz görüntülü sohbet
şırnak sohbet uygulamaları
Niğde Canlı Sohbet
gümüşhane rastgele görüntülü sohbet uygulaması
AC472
ReplyDeleteKars Rastgele Canlı Sohbet
görüntülü sohbet yabancı
ücretsiz sohbet siteleri
adıyaman kızlarla rastgele sohbet
manisa mobil sohbet chat
kastamonu ücretsiz sohbet uygulaması
ığdır en iyi görüntülü sohbet uygulamaları
şırnak kadınlarla sohbet
Hatay Görüntülü Sohbet Siteleri
1E722
ReplyDeleteLinkedin Takipçi Satın Al
Binance Referans Kodu
Görüntülü Sohbet
Okex Borsası Güvenilir mi
Linkedin Takipçi Hilesi
Coin Kazma
Soundcloud Reposts Hilesi
Kripto Para Nasıl Çıkarılır
Likee App Takipçi Satın Al
57122
ReplyDeleteMexc Borsası Güvenilir mi
Linkedin Beğeni Satın Al
Loop Network Coin Hangi Borsada
Twitter Retweet Hilesi
Kripto Para Madenciliği Siteleri
Nonolive Takipçi Hilesi
Kripto Para Nasıl Çıkarılır
MEME Coin Hangi Borsada
Hexa Coin Hangi Borsada
8F030
ReplyDeletehuobi
canlı sohbet uygulamaları
gate io
bybit
telegram kripto kanalları
ilk kripto borsası
binance referans kodu
bitexen
bingx
C74FF
ReplyDeletebinance
canlı sohbet ucretsiz
okex
kraken
mexc
kucoin
telegram en iyi kripto grupları
papaya meyvesi
bingx
نفخ المجاري بالاحساء dq6xHV0tNt
ReplyDelete39xDlbHhKr
ReplyDeleteشركة رش حشرات بالاحساء 3V0nxrurPO
ReplyDeleteشركة تنظيف مدارس بالاحساء dPcJasu4ko
ReplyDeleteشركة مكافحة حشرات بالاحساء ppgxQBaVlF
ReplyDeleteشركة عزل مواسير المياه بالدمام y5AEUUSNXq
ReplyDeleteشركة مكافحة النمل الابيض بخميس مشيط PkYorAwlOI
ReplyDeleteشركة تنظيف فلل بالقطيف
ReplyDeleteKldFjg