Same ajaxErrorHandler called for multiple exceptions

Community Driven Extensions Project
Post Reply
vovan
Posts: 7
Joined: 29 Mar 2014, 09:07

16 Jun 2014, 14:04

Hello!

Why for every thrown exception always called same(first) ajaxErrorHandler ?
This code is from showcase. I just added form for buttons and chaged titles of error handlers.

Code: Select all

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:pe="http://primefaces.org/ui/extensions"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <!-- With the exception of texts, you can add the button its own JavaScript function.  You can define texts: -->  
        <pe:ajaxErrorHandler  
            title="Error1"  
            body="Server return exception  {error-name} with description {error-message}"  
            button="Hide"  
            widgetVar="myAjaxErrorHandler" buttonOnclick="myAjaxErrorHandler.hide()"  />  

        <!-- In title and body you can use HTML tags too, because the values are not escaped. -->  
        <pe:ajaxErrorHandler  
            title="Error2"  
            body="Server return exception  {error-name} with description <b>{error-message}</b>"  
            button="Hide"  
            widgetVar="myAjaxErrorHandler" buttonOnclick="myAjaxErrorHandler.hide()"  
            type="javax.faces.application.ViewExpiredException" />  


        <!-- An example of protocol, where title and body are defined through <f:facet name="title"> and/or <f:facet name="body"> -->  
        <pe:ajaxErrorHandler type="java.lang.IllegalStateException" button="Close warning!">  
            <f:facet name="title">  
                Error3 <span style="color: red;">{error-name}</span>  
            </f:facet>  
            <f:facet name="body">  
                <div>  
                    <h:form>  
                        <p:tabView >  
                            <p:tab title="Message">  
                                <h:panelGrid columns="2">  
                                    <h:outputLabel value="Error message:" />  
                                    <h:outputText value="{error-message}" style="font-size: 1.2em;color:navy;" />  

                                    <h:outputLabel value="Server name:" />  
                                    <h:outputText value="{error-hostname}"  style="font-size: 1.2em;color:navy;"/>  
                                </h:panelGrid>  

                            </p:tab>  
                            <p:tab title="Detail">  
                                <div style="overflow: auto; height: 300px; width: 700px;">  
                                    {error-stacktrace}  
                                </div>  
                            </p:tab>  
                        </p:tabView>  
                    </h:form>  
                </div>  
            </f:facet>  
        </pe:ajaxErrorHandler>  
        
        <h:form>
            <!-- AJAX actions, which throw exceptions -->  
            <p:commandButton action="#{ajaxErrorHandlerController.actionThrowNullPointer}"  
                             value="Example first definition" />  
            <p:commandButton action="#{ajaxErrorHandlerController.actionSimulateViewExpiredException}"  
                             value="Example second definition" />  
            <p:commandButton action="#{ajaxErrorHandlerController.actionWrappedException}"  
                             value="Example third definition" />  
        </h:form>

    </h:body>
</html>
Here what i get if i press every button:

Image
Image
Image

How can i set different handlers for different exceptions ?
Thank you.

User avatar
sudheer
PrimeFaces Core Developer
Posts: 4345
Joined: 16 Oct 2011, 19:19
Location: Singapore

16 Jun 2014, 14:15

Might be because of same widgetVar names? Please try with unique values.

But ajaxErrorHandler invoked based on exception type only.
Author,Speaker
https://twitter.com/sudheerjonna
Github: https://github.com/sudheerj
Website http://sudheerjonna.com/

___________________
Sudheer Jonna

vovan
Posts: 7
Joined: 29 Mar 2014, 09:07

16 Jun 2014, 14:47

sudheer wrote:Might be because of same widgetVar names? Please try with unique values.

But ajaxErrorHandler invoked based on exception type only.
No changes :(

May someone try run my code ? Maybe i have problems with server or somethig...

Bean code:

Code: Select all

import javax.enterprise.context.RequestScoped;
import javax.faces.FacesException;
import javax.faces.application.ViewExpiredException;
import javax.faces.context.FacesContext;
import javax.inject.Named;

@Named
@RequestScoped  
public class AjaxErrorHandlerController {  
  
    public String actionThrowNullPointer() {  
        throw new NullPointerException("This is my null pointer exception!");  
    }  
  
    public String actionWrappedException() {  
        Throwable t = new IllegalStateException("This is wrapped illegal state exception!");  
        throw new FacesException(t);  
    }  
  
    public String actionSimulateViewExpiredException() {  
        throw new ViewExpiredException("This is simulated ViewExpiredException",  
                                       FacesContext.getCurrentInstance().getViewRoot().getViewId());  
    }  
}  
     

User avatar
sudheer
PrimeFaces Core Developer
Posts: 4345
Joined: 16 Oct 2011, 19:19
Location: Singapore

16 Jun 2014, 15:20

Not this way.If you can make it as simple maven proj then only it will be easy to test your sample app.
Author,Speaker
https://twitter.com/sudheerjonna
Github: https://github.com/sudheerj
Website http://sudheerjonna.com/

___________________
Sudheer Jonna

Post Reply

Return to “Extensions”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 13 guests