FROM THE BLOG

ADF Tip: Cascading (dependent) LOV with mandatory (required) fields.

This post will assume that you have, at this point, implemented your Dependent LOV, using ADF Business Components the following;

  • You have View Objects and you have created  View Criterias.
  • Create some LOVs for View Objects attributes.
  • Specifying View Criteria over the View Accessors that retrieves your LOV. (implementing the dependency)

We want a Cascading LOV; Region -> Country -> Location.

We have based this example in Oracle HR Schema;

adf_dependent_lov_1

We have created a new transient VO, lets call it MySearchVO with 3 transient attributes (to populate our LOVs);

adf_dependent_lov_16

Also, we have set all three attributes to be mandatory – this is how the source code looks for RegionId;

adf_dependent_lov_mandatory_1

If we run the application we see;

Selection_063

Since RegionId and CountryId have autoSubmit = true (to update the values of the dependant LOV) and there is a partialTrigger on the PanelForm pointing to the first 2 SelectOneChoices components, this is what happens when trying to update the region;

Selection_064

In order to fix this behaviour and trigger the validation just when pressing the submit button, we need to handle everything from our backingBean – first thing is to remove the partial triggers from our form. Also, we need to bind our parent container in the bean (to refresh it after your selection). And finally, we need to add the following valueChangeListener to the components triggering the validation; in our case, RegionId and CountryId;

public void updateModel(ValueChangeEvent valueChangeEvent) {
// Update Model
valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());
// Refresh the form
AdfFacesContext.getCurrentInstance().addPartialTarget(form);
// Avoid triggering the validation
FacesContext.getCurrentInstance().renderResponse();
}

This is how the code of our Java Bean looks;

Selection_065

After that, you should be able to change and update your dependent and mandatory LOVs.

Selection_066

Leave a comment

Your email address will not be published.