Navigate to another page on value change event of ADF input component

Sharing is Caring

Recently I have seen a thread on OTN forum in that user want to navigate to another page from one-page on valueChangeListener of the input component.

First Method-
This is a simple piece of code to perform navigation to specific page , Use it in ValueChangeListener directly

 FacesContext facesContext = FacesContext.getCurrentInstance();
 facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext, null, "controlFlowName");

Second Method-
ValueChangeListener fires when value of input component changes but it is not meant for navigation, For navigation we use buttons and links with Action property
But for this requirement we have to be a bit tricky, We can queue button Action on value change listener of inputText to navigate to another page
Now first value change listener will be executed and then it’ll queue button action to execute and as final outcome user will be able to navigate


See how to implement this scenario-

I have created two pages in adfc-config.xml (default unbounded taskFlow)

Dropped an af:inputText and a button on page1

 <af:inputText label="Enter Value greater than 100 to Navigate" id="it1"
                                  valueChangeListener="#{viewScope.NavigateFromInputTextBean.inputTextVCE}"
                                  autoSubmit="true">
                        <af:convertNumber/>
                    </af:inputText>
                    <af:button text="button 1" id="b1" action="goToPage2"
                               binding="#{viewScope.NavigateFromInputTextBean.buttonBind}"/>

Next is that I want to navigate to page2 when user enter a value greater than 100 in inputText, So for that created a value change listener in bean and queued this button action after checking condition

import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;

import oracle.adf.view.rich.component.rich.nav.RichButton;

//Component Binding of af:inputText
private RichButton buttonBind;

public void setButtonBind(RichButton buttonBind) {
this.buttonBind = buttonBind;
}

public RichButton getButtonBind() {
return buttonBind;
}

/**Method to navigate from page1 to page2 if input text value is greater than 100
* @param valueChangeEvent
*/
public void inputTextVCE(ValueChangeEvent valueChangeEvent) {
if (valueChangeEvent.getNewValue() != null) {
Integer val = Integer.parseInt(valueChangeEvent.getNewValue().toString());
if (val > 100) {
//Code to queue button ActionEvent
FacesContext facesContext = FacesContext.getCurrentInstance();
UIViewRoot root = facesContext.getViewRoot();
//Pass component client id to find button
RichButton button = (RichButton) root.findComponent(buttonBind.getClientId());
//Create and queue ActionEvent
ActionEvent actionEvent = new ActionEvent(button);
actionEvent.queue();
}
}
}

All Done 🙂 You can set visible false for button if you don’t want it on page
Run and check application
Enter a value greater than 100-

Control moves to second page-

Sample ADF Application – Download
Cheers 🙂 Happy Learning

Related Posts

I’m an Oracle ACE, Blogger, Reviewer,
Technical Lead working on Oracle ADF

0 thoughts on “Navigate to another page on value change event of ADF input component”

  1. Here my requirement is when in page1 i give Client name in selectonechoice and generate usecases then for selected client names only i will get usecases in the page2 navigation
    Not like above requirement value greater than 100
    please send me solution for this ….

Leave a Reply

Your email address will not be published. Required fields are marked *