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.

Comments:

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.

Posted by Bogdan on May 27, 2011 at 05:33 AM IST #

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"/>

Posted by shantala.sankeshwar@oracle.com on June 08, 2011 at 03:51 AM IST #

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

Posted by guest on February 23, 2012 at 11:58 AM IST #

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?

Posted by shantala on February 23, 2012 at 02:56 PM IST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Tips and Tricks from Oracle's JDeveloper & ADF QA

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today