ADF lifecycle is developed on top of JSF life cycle. Any JSF page is a run time representation of a Tree which has child components (components can be input components, display components or action components). Once the user request got initialized the JSF page request life cycle begins and the eventual result of the cycle will be a component tree that has to be shown for the initialized request. Here are the phases.
1.The value of the EL expression, Component value and the string value itself are null in Apply Request Values phase.
3. After Process Validation phase the component value printed is not null any more but still the EL expression value and string value is null as the values are not submitted to model.
5. ActionListener and Action methods of the button are executed during Invoke Application phase. (ActionListener got executed first and then Action method got executed). Business logic is performed here.
6. Hence during the time of RenderResponse phase, you can see the values printed for the EL Expression, Component value and string value are same as it is saved in the application state. Here we are not showing a response to the user, how ever you can create a string and display it to the user. For Instance "Record Saved Succesfully."
public class LifeCycleDemoBean {
private String testStringValue= null;
private RichInputText textBox;
public LifeCycleDemoBean() {
}
public String saveAction() {
System.out.println(" Executed saveAction() in "+FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("oracle.adfinternal.view.faces.lifecycle.CURRENT_PHASE_ID"));
BindingContext bindingContext = BindingContext.getCurrent();
BindingContainer bindings = bindingContext.getCurrentBindingsEntry();
OperationBinding method = bindings.getOperationBinding("Commit");
method.execute();
return null;
}
public void saveActionListener(ActionEvent actionEvent) {
System.out.println(" Executed saveActionListener() in "+FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("oracle.adfinternal.view.faces.lifecycle.CURRENT_PHASE_ID"));
System.out.println(" Executed saveActionListener(), Last Name #{bindings.LastName.inputValue} Expression value:"+evaluateEL("#{bindings.LastName.inputValue}"));
}
public void lastNameChangeListener(ValueChangeEvent valueChangeEvent) {
System.out.println(" Executed lastNameChangeListener() in "+FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("oracle.adfinternal.view.faces.lifecycle.CURRENT_PHASE_ID"));
}
public void lastNameValidator(FacesContext facesContext,
UIComponent uIComponent, Object object) {
System.out.println(" Executed lastNameValidator() in "+FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("oracle.adfinternal.view.faces.lifecycle.CURRENT_PHASE_ID"));
}
public void beforePhaseListener(PhaseEvent phaseEvent) {
System.out.println(" Before Phase:"+phaseEvent.getPhaseId()+" Last Name #{bindings.LastName.inputValue} Expression value:"+evaluateEL("#{bindings.LastName.inputValue}"));
if(this.getTextBox()!=null)
System.out.println(" Component Value of Test String:"+this.getTextBox().getValue());
else
System.out.println(" Component Value of Test String:"+null);
System.out.println(" Value of the actual Test String:"+testStringValue);
}
public void afterPhaseListener(PhaseEvent phaseEvent) {
System.out.println(" After Phase:"+phaseEvent.getPhaseId()+" Last Name #{bindings.LastName.inputValue} Expression value:"+evaluateEL("#{bindings.LastName.inputValue}"));
if(this.getTextBox()!=null)
System.out.println(" Component Value of Test String:"+this.getTextBox().getValue());
else
System.out.println(" Component Value of Test String:"+null);
System.out.println(" Value of the actual Test String:"+testStringValue);
System.out.println();
}
public static Object evaluateEL(String el){
FacesContext facesContext = FacesContext.getCurrentInstance();
ELContext elCtx = facesContext.getELContext();
ExpressionFactory expFactory =facesContext.getApplication().getExpressionFactory();
ValueExpression valExp =expFactory.createValueExpression(elCtx, el, Object.class);
return valExp.getValue(elCtx);
}
public void setTestStringValue(String testStringValue) {
this.testStringValue = testStringValue;
}
public String getTestStringValue() {
return testStringValue;
}
public void setTextBox(RichInputText textBox) {
this.textBox = textBox;
}
public RichInputText getTextBox() {
return textBox;
}
}