Thursday, September 5, 2019

ADF BC Multiple LOVs for VO's attribute

Everybody knows how to define LOV for view object's attribute. But what if depending on application's logic it's needed to get values for LOV from different sources or with completely different conditions. For suer, it's possible to define complex SQL query for LOV's VO and play with it's parameters. But most likely we'll get performance issue using this approach. And what we should do if it's required to use different display values for different use cases?


ADF BC allows us to define more than one LOV per attribute.
Let's say I have VO representing some form to input address information. It has attribute for country and attribute for region or state. If country is USA, user should select one of the US states, if country is India, user should select Indian state, in other cases user doesn't need any LOV and should input region manually.

I defined two LOVs for Regionstate attribute. Each of them retrieves values from its own data source  (US states and Indian states). In order to switch LOVs I defined new transient attribute StateLovSwitcher. The value of this attribute should contain proper LOV's name.



StateLovSwitcher's value is Groovy expression derived and defined as:


I'm going to provide user by two input controls for Regionstate field. For US and India user needs SelectOneChoice in other cases he needs InputText. I'm using af:switcher showing SelectOneChoice if  StateLovSwitcher has value and InputText if it doesn't.
1
2
3
4
5
6
7
8
9
10
11
12
<af:switcher defaultfacet="input" facetname="#bindings.StateLovSwitcher.inputValue==null?'input':'select'}" id="s1">
  <f:facet name="input">
    <af:inputtext value="#{bindings.Regionstate1.inputValue}">
      ...
    </af:inputtext>
  <f:facet name="select">
    <af:selectonechoice binding="#{MainBean.regionLOV}" value="#{bindings.Regionstate.inputValue}">
        ...
    </af:selectonechoice>
</f:facet>
</f:facet>
</af:switcher>

And finally in order to get it working fine we need to clean region's value if country changes.

1
2
3
4
public void countryListener(ValueChangeEvent valueChangeEvent) {
   if (valueChangeEvent.getOldValue()!=valueChangeEvent.getNewValue())
          regionLOV.setValue(null); 
 }

No comments:

Post a Comment