jeudi 18 juin 2015

Partial update current page in case of error occures

We handle exceptions in the JSF based application with class that extends ExceptionHandlerWrapper. For expired session exception we need just redirect user to the corresponding page - so we have something like:

    public void handle() {
        final Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator();
        while (i.hasNext()) {
            ExceptionQueuedEvent event = i.next();
            ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();
            Throwable t = getRootCause(context.getException());
            if (t instanceof ViewExpiredException) {
                try {
                    final FacesContext fc = FacesContext.getCurrentInstance();                      
                    fc.getApplication().getNavigationHandler().handleNavigation(fc, null,"/sessionTimedOut.xhtml");
                    fc.renderResponse();
                } finally {
                    i.remove();
                }
            }
        }
    }

Now I got a new task - there is a block "error" in the main template.

<h:panelGroup id="exceptionAreaHpbx" layout="block" class="boxed error-block" rendered="#{not empty sessionScope.errorCodes || not empty sessionScope.errorCode}">

When certain exceptions occur I need to update this block for displaying error messages to the user.

Is there any approach to reach this goal using the same handle() function?

User should stay at the same page - so it must be ajax. Is it possible?

Aucun commentaire:

Enregistrer un commentaire