X
  • EJB
    February 9, 2011

Simulating LOV (List Of Values) in EJB

This Use case simulates lov(list of values) in EJB.It uses HR Schema with locations & countries tables.Based on the value selected in lov,it performs query in database & displays result in ADF Form.

Steps

Let
us suppose that we have created Java EE Web Application with Entities
from locations & countries tables.

Add custom NamedQuery to Locations.java bean that returns the list of Locations for the respective countryId parameter:

 @NamedQuery(name = "Localtions.FindByCountryId", query = "select o from Locations o where o.countries.countryId = :countryId") 


Create Stateless Session Bean and expose the Named Queries through the Session Facade.

EntityMethods.jpeg

















And then generate Datacontrol from SessionBean local interface.

Create LovTestpage.jspx page in ViewController project & drop countryId parameter as selectOneChoice

selectOneChoice.jpeg

Add countriesFindAll as List Data Source in the Edit List Binding Editor

Adddatasource.JPG

Add valueChangeListener to selectOneChoice by creating Managed Bean testBean.java & valueChangeListenerMethod in this Managed Bean .

public void valueChangeListenerMethod(ValueChangeEvent valueChangeEvent)
 {
  // This method passes the selected value to the method & method is executed
      
BindingContainer bindings = getBindings();
OperationBinding operationBinding =  bindings.getOperationBinding("getLocaltionsFindByCountryId");
operationBinding.getParamsMap().put("countryId", valueChangeEvent.getNewValue().toString());
Object result = operationBinding.execute();

 }
public static BindingContainer getBindings()
 {
            return BindingContext.getCurrent().getCurrentBindingsEntry();
 }

By Default the selectOneChoice returns index in its valueChangeListener method,in order to return the selected value,modify these entries:

a)Goto the page Definition file & add a List Binding:
     <list ListOperMode="navigation" 
     IterBinding="countriesFindAllIterator"
     ListIter="countriesFindAllIterator" id="countryIdLOV"></list>

b)SelectOneChoice code in jspx page should be:

<af:selectOneChoice value="#{testBean.countryValue}" label="#{bindings.countryId.label}"
  autoSubmit="true" required="#{bindings.countryId.hints.mandatory}"
  shortDesc="#{bindings.countryId.hints.tooltip}" id="soc1" valueChangeListener=
  "#{testBean.valueChangeListenerMethod}" >           
  <af:forEach items="#{bindings.countryIdLOV.iteratorBinding.allRowsInRange}" var="var1">
   <af:selectItem id="si2" label="#{var1.dataProvider.countryId}"
    value="#{var1.dataProvider.countryId}"/>
  </af:forEach>
</af:selectOneChoice>


Open LovTestpage.jspx page & drop Locations as ADF Form

form1.JPG



Run the above page & note that the form shows the location details of the selected countryId

Displaypage.JPG
Now lets try to extend the same use case to achieve Dependent lov's.

In the same above jspx page,drop Locations node as selectOneChoice with display attribute as 'locationId'.Try to run the page & note that the Locations list changes dynamically based on the countryId selection.

Join the discussion

Comments ( 4 )
  • Bogdan Friday, May 27, 2011
    Is there a solution that doesn't use af:forEach tag, but still gets the data directly from the data control? I tried to use the f:selectItems tag, but couldn't make it work directly with the data control, only through a managed bean that calls the EJB.
  • shantala.sankeshwar@oracle.com Tuesday, June 7, 2011
    You can use f:selectItems as well,in this case "{bindings.countryId.attributeValue}" will give the selected value:
    <af:selectOneChoice value="#{bindings.countryId.inputValue}"
    label="#{bindings.countryId.label}" required="{bindings.countryId.hints.mandatory}"
    autoSubmit="true" shortDesc="#{bindings.countryId.hints.tooltip}"
    id="soc1">
    <f:selectItems value="#{bindings.countryId.items}" id="si1"/>
    </af:selectOneChoice>
    <af:outputText id="ot1" value="#{bindings.countryId.attributeValue}"
    partialTriggers="soc1"/>
  • guest Thursday, February 23, 2012

    Hi could you please give me more details on the LOV Creation through EJB 3.0 as i was not able to create teh same as you did


  • shantala Thursday, February 23, 2012

    Can you please explain me the exact issue you are facing & the step that you are not able to execute.Also please provide me the Jdeveloper version that you are using to develop this usecase?


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.