## Error checking mechanism.

The Photo Album application has a global mechanism for errors checking. You become informed about the error each time it occurs. It is possible because the main page of the application `web/src/main/webapp/index.xhtml` includes the `web/src/main/webapp/includes/misc/errorPanel.xhtml` :

                <r:outputPanel id="errors" ajaxRendered="true" layout="block">
                    <h:panelGroup rendered="{errorHandlerBean.errorExist}">
                        <r:popupPanel id="errorPanel" show="true" minWidth="300" minHeight="200" autosized="true">
                            …
                        </r:popupPanel>
                    </h:panelGroup>
                </r:outputPanel>

Here is the listing of the `errorHandlerBean` class:

            @Named
            @RequestScoped
            public class ErrorHandlerBean {
                private List<String> errors = new ArrayList<String>();

                public List<String> getErrors() {
                    return errors;
                }

                public boolean isErrorExist() {
                    return errors.size() > 0;
                }

                public void addToErrors(@Observes @EventType(Events.ADD_ERROR_EVENT) SimpleEvent se) {
                    errors.add(se.getMessage());
                }
            }

The error panel contains the <r:outputPanel> component that is rendered on every Ajax request ( `ajaxRendered="true"` ). If an error is occurred the `isErrorExist()` method of `errorHandlerBean` class returns "true", so the <h:panelGroup> component is rendered. In order to show nested <r:popupPanel> component with the collected errors the "show" attribute should be set to "true".

The `addToErrors()` method is annotated with `@Observes` annotation, thus it observes all events with `ADD_ERROR_EVENT` constant and adds errors to the `errors` List.