I had a monolithic application, in which window.location.href was working as according to what I needed. But now I changed my application to microservices architecture. So, API is running on a separate server while UI is on another server.
Now for my xhtml file, I have a commandButton
in my employeelist.xhtml
.
How do I stop my oncomplete
process windows redirect if there is an error (API is down / or any other errors)?
Currently, it logs the errors but FaceMessages are not displayed and also, the page is redirected to employee_details.xhtml but there are no details in that page as onEmployeeSelect
method throws an error.
<p:commandButton value="#{employee.employeeId}">
<p:ajax process="@this" listener="#{employeeBean.onEmployeeSelect(employee)}"
oncomplete="window.location.href='employee_details.xhtml'" />
</p:commandButton>
Backingbean is
public void onEmployeeSelect(EmployeeDefinition employeeVO) {
try{
//calls API
if (success) {
//show employee details
}
}
catch(Exception ex){
//if API is not reachable
addMessage(FacesMessage.SEVERITY_ERROR, ERROR, ex.getMessage());
}
}
New to JSF/Java, any help would be appreciated.