I am working on JSF2 application and I am trying to add exception handling to all my xhtmls either by showing inline messages or an error pop up.
For example, if a service exception happens in the backing bean I am wrapping it in my custom UI exception and rethrowing it as below where the second parameter indicates whether to inform the user about the exception using a pop up or an inline message.
throw new UIException(e, true);
In my exception handler wrapper, I am intercepting this exception and based on the second parameter I am trying to show the error in pop up or inline. For the pop up, I have a rich:popupPanel which I have included in the base page where all the xhtmls are included in the application. So, in the exceptionHandler wrapper, I add this pop up to the render ids dynamically as below.
FacesContext.getCurrentInstance().getPartialViewContext()
.getRenderIds().add("popupForm:popupErrorPanelGroup");
For the inline messages, I want to add a inline snippet in my base xhtml and want to to show the error in line message in a similar fashion. The problem with this approach is the message positioning is not right, the inline message is supposed to be shown at the top of the individual form but now it shows up at the top of the application. For this I have to include my inlineexception xhtml in each and every xhtml manually.
Inline Exception xhtml:
<h:panelGroup styleClass="error" rendered="#{errorInlineBackingBean.showError}">
<h:outputText id="errorText"
value="#{errorInlineBackingBean.errorMsg}" />
</h:panelGroup>
Is it possible to include this inlineException in the base page similar to the pop up approach and have it shown in any forms in the application? I want to avoid including the repeated code of including it in every xhtml or placing the h:messages tag in all the xhtmls.