primefaces and redirection to error page

UI Components for JSF
Post Reply
User avatar
sc.tassadar
Posts: 9
Joined: 16 Jan 2011, 10:32
Location: Algiers - ALGERIA

16 Jan 2011, 10:48

Hi all, iam working on a small prime project (working also on iceface project ) .
adding elements to database using prime is ok for me (all CRUD operations ).
for exception handling iam using:

Code: Select all

<error-page> 
<exception-type>java.lang.Exception</exception-type> 
<location>/error.xhtml</location> 
</error-page> 
to handle all errors using web.xml

i tried to simulate an exception ( by adding an element with same id with and existing one in database in order to have a key violation )

the exception is thrown (i see that on glassfish log)
but the redirection to the customized error page is not working : iam staying on the form page.

is <error-page> ignored ?
i tried with

Code: Select all

 <h:commandButton value="add"  action="#{controllerlist.docreate}" />
instead of

Code: Select all

 <p:commandButton value="add"  action="#{controllerlist.docreate}" />
and the redirection to error page worked !?

any hint on this ?

iam using :
NETBEANS 6.9.1
primefaces
DATABASE: MySQL
glassfish server 3
all browsers (IE/Firefox/chrome)

ps : in primefaces after not being redirected to error page , i can insert elements in database using the same page , on icefaces the button is frozen and dont fire any request .
Glassfish V3.0.1, Primefaces 2.2.Final , NetBeans 6.9.1

User avatar
sc.tassadar
Posts: 9
Joined: 16 Jan 2011, 10:32
Location: Algiers - ALGERIA

16 Jan 2011, 11:23

even a redirection after a succesful operation is not working :
public String docreate() {

if(regionEJB.createregion(region)==true){
return "created";
}else{
return "error";

}
}
but working with
<h:commandButton value="add" action="#{controllerlist.docreate}" />
iam missing something ?
Glassfish V3.0.1, Primefaces 2.2.Final , NetBeans 6.9.1

User avatar
sc.tassadar
Posts: 9
Joined: 16 Jan 2011, 10:32
Location: Algiers - ALGERIA

16 Jan 2011, 12:18

Resolved :

i have to add ajax="false"

<p:commandButton value="add" action="#{controllerlist.docreate}" ajax="false" />

i have tears ...
Glassfish V3.0.1, Primefaces 2.2.Final , NetBeans 6.9.1

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

16 Jan 2011, 12:35

You need to do redirect not forward for navigation after ajax;

Code: Select all

public String docreate() {

if(regionEJB.createregion(region)==true){
return "created?faces-redirect=true";
}else{
return "error?faces-redirect=true";

}
}
For exception handling, use JSF's exception handling apis not servlet apis.

healeyb
Posts: 365
Joined: 07 Apr 2010, 16:05

17 Jan 2011, 02:13

This is from my list of "bugs and workarounds":

6. When I navigate to an action= with h:commandButton/p:commandButton (and
possibly commandLink also) when using Ajax (update= on p: or child
f:ajax tag on h:) then when an exception is thrown in the action
routine which it handled in the web.xml page the error page it not
navigated to. It's best to forcibly navigate to the error page if an
exception occurs.

What I do is have a method gotoPage() that lives in an abstract class
that is inherited by all my backing beans, and when I hit a problem I
just call gotoPage("errorPage"). There are just too many problems with
the error-page mechanism, it even behaves differently according to
the PROJECT_STAGE setting I believe.

Code: Select all

void gotoPage(String page) {

        // Usage example: gotoPage("errorPage");
        
        FacesContext fc = FacesContext.getCurrentInstance();
        NavigationHandler nav = fc.getApplication().getNavigationHandler();
        nav.handleNavigation(fc, null, "/" + page + "?faces-redirect=true");
        fc.renderResponse();
}
Regards,
Brendan.

Manu206
Posts: 33
Joined: 25 Mar 2011, 16:15

07 Apr 2011, 13:08

I'm using a similar solution like "gotoPage(String page)".

Is there a way to pass the p:messages through the error page?
Primefaces 3.5
Mojarra 2.1.9
Netbeans 7.3.x
Glassfish 3.2.1

User avatar
bumble.bee
Posts: 723
Joined: 29 Sep 2010, 21:39
Location: United States

07 Apr 2011, 15:02

If you want to have FacesMessages which survive a redirect you could try to use the flash scope's keepMessages feature. However, it doesn't seem to work so good. There is a better solution discussed here:

http://ocpsoft.com/java/persist-and-pas ... redirects/

The error handling code in JSF is a big fat hairy hot mess.

It should probabaly be mentioned that you can create a custom error handler (but it seems to have some limitations with ajax). See :

http://primefaces.prime.com.tr/forum/vi ... f=3&t=8312

and

http://primefaces.prime.com.tr/forum/vi ... f=3&t=5909

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 62 guests