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.
And then generate Datacontrol from SessionBean local interface.
Create LovTestpage.jspx page in ViewController project & drop countryId parameter as selectOneChoice
Add countriesFindAll as List Data Source in the Edit List Binding Editor
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
Run the above page & note that the form shows the location details of the selected countryId
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.
<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"/>
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
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?