Exception Handling
- by raghu.yadav
Here is the few links on which andre had demonstrateddifferences-of-handling-jboexception-in
handling-exceptions-in-oracle-ui-shell
However in this post we can see how to display exception in popup being in the same page. I use similar usecase as andre however we'll not be using Exception Handling property from taskflow, instead we use popup and invoke the same programmatically.
This is a dynamic region example where user can select jobs or locations links to edit the records of corresponding tables being in the same page and click commit to save changes.
To generate exception we deliberately change commit to CommitAction in commit action binding code created in the bean (same as andre) and catch the exception and add brief description of exception into #{pageFlowScope.message}. Drop Popup component after Commit button and add dialog within in popup button, bind the popup component to backing bean and invoke the same in catch clause as shown below.
public String Commit() {
try{
BindingContainer bindings = getBindings();
OperationBinding operationBinding = bindings.getOperationBinding("CommitAction");
Object result = operationBinding.execute();
if (!operationBinding.getErrors().isEmpty()) {
return null;
}
}catch (NullPointerException e) {
setELValue("#{pageFlowScope.message}", "NullPointerException...");
e.printStackTrace();
String popupId =
this.getPopup().getClientId(FacesContext.getCurrentInstance());
PatternsPublicUtil.invokePopup(popupId);
}
return null;
}
}
private void setELValue(String el, String value) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
ExpressionFactory expressionFactory =
facesContext.getApplication().getExpressionFactory();
ValueExpression valueExp =
expressionFactory.createValueExpression(elContext, el, Object.class);
valueExp.setValue(elContext, value);
}
.