Skip to main content

error page in jsf

11 replies [Last post]
xsi
Offline
Joined: 2008-06-25
Points: 0

hello all

i programmed an datatable in jsf , it calls via a managedbean these procedure :
public Result getAll() throws SQLException

when these page generates an sqlerror i got an internal error 500, is there a way to redirect to an error page in the managedbean ?

thanks all

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Ryan Lubke

On 3/21/09 7:41 AM, Lincoln Baxter, III wrote:
> Ok, I can reproduce this now... take a look at the composite component
> below.
>
> By deleting the tag, I am able to get proper rendering.
>
> This is a layout component, and is used in several places in the
> page... I'm guessing that when the component
> repeats, it is always adding itself to the HEAD component again, but
> not assigning itself a unique ID.
This should be resolved in last night's nightly.
>
>
>
> > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> > xmlns:h="http://java.sun.com/jsf/html"
> xmlns:f="http://java.sun.com/jsf/core"
> xmlns:ui="http://java.sun.com/jsf/facelets"
> xmlns:composite="http://java.sun.com/jsf/composite">
>
>
>
>
> > default="false" />
>
>

>
>
> * *
>
>

>

>


> > style="float: right; position:relative; top:-18px; left: -3px;">
> > rendered="#{compositeComponent.attrs.collapsible eq 'true'}">
> > onclick="return collapse(event, '#{compositeComponent.clientId}');"
> title="Collapse">
>
>

>
>

>

>

>
> > rendered="#{!empty compositeComponent.facets.content}">
>
>

>

>
>
>
>

[att1.html]

Jan-Kees van Andel

Well, I don't like to do any error handling or navigation inside managed
beans, but if you insist, you can grab the NavigationHandler via the
FacesContext and call it directly. Don't forget to call
FacesContext.responseComplete() afterwards to short circuit the lifecycle,
like this.

try {
// Some data access code here
} catch (SQLException e) {
FacesCOntext fc = FacesCOntext.getCurrentInstance();
fc.getApplication().getNavigationHandler().handleNavigation(fc,
"#{bean.actionName}", "toErrorPage");
fc.responseComplete();
}

And the faces-config.xml:



toErrorPage
/errorPage.xhtml


If you don't want to use a redirect, for example, if you would like to
display some error data inside the error page, you need to make two changes.
The first is obvious, remove the . The second one is replace
fc.responseComplete() to fc.renderResponse().

I think both options should work fine.

But again, the managed bean is not the right place for default error
handling or navigation. Managed beans probably get large and ugly when you
do these kind of things often.

Regards,

Jan-Kees

2008/10/1

> hello all
>
> i programmed an datatable in jsf , it calls via a managedbean these
> procedure :
> public Result getAll() throws SQLException
>
> when these page generates an sqlerror i got an internal error 500, is there
> a way to redirect to an error page in the managedbean ?
>
> thanks all
> [Message sent by forum member 'xsi' (xsi)]
>
> http://forums.java.net/jive/thread.jspa?messageID=302748
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
>
[att1.html]

xsi
Offline
Joined: 2008-06-25
Points: 0

thanks

but if you don like to put redirection im managed beans, where do i put the code to redirect to an errror page when the managed beans trigger it ?

thanks for the response

Jason Lee

On Oct 2, 2008, at 9:28 AM, webtier@javadesktop.org wrote:

> thanks
>
> but if you don like to put redirection im managed beans, where do i
> put the code to redirect to an errror page when the managed beans
> trigger it ?

You might look up the error-page element for web.xml. For example,
here's how the GlassFish v3 Admin Console handles ViewExpiredExceptions


javax.faces.application.ViewExpiredException exception-type>
/

Here, we capture only this exception. If you want to capture 500
errors, for example, you can specify that instead of the exception-
type, though I can't remember what the element name is. Hopefully,
the text above will give you enough to google with.

Jason Lee
Senior Java Developer
GlassFish Administration Console

Sun Microsystems, Inc.
Phone x31197/+1 405-343-1964
Email jasondlee@sun.com
Blog http://blogs.sun.com/jasondlee
Blog http://blogs.steeplesoft.com

[att1.html]

xsi
Offline
Joined: 2008-06-25
Points: 0

thank you very much

nhassona
Offline
Joined: 2009-02-25
Points: 0

i have a web application. i used glass fish v2 with netbeans 6.5, Jsf 1.2.
i want to handle some Business exceptions or any exception and redirect to error page.
That is my code

// managed bean "This is action on a button"
public String testAction()throws RuntimeException{
//some codes
searchService.businessLogicMethod();
}

// search service class

public void businessLogicMethod( ) throws RuntimeException {

System.out.println("BusinessLogic Method Called");
// what ever code
throw new RuntimeException();
}
and define all error code and type in web.xml


java.lang.RunTimeException
/errorPage.jsp

500
/errorPage.jsp

503
/errorPage.jsp

[b]But it doesn't redirect neither my error page OR server error page.
It stopped at the same page.[/b]

[b]Even if any Unhandled exception fired. it will be redirected to my error page.[/b]

Please any one can help me,
Thanks advice.

anroo
Offline
Joined: 2009-02-17
Points: 0

i have the same problem.

Do you solve the problem?

Lincoln Baxter, III

As of the last nightly (downloaded friday the 20th) Looks like component
name generation is having some issues... this is a pretty plain
component tree, but has a duplicate ID? Anyone else getting this?

SEVERE: Servlet.service() for servlet default threw exception
com.ocpsoft.socialpm.exceptions.SiteRuntimeException:
javax.servlet.ServletException: Component ID j_id1442058466_55f4108a has
already been found in the view. See below for details.
+id: j_id1
type: javax.faces.component.UIViewRoot@198d2cc
+id: javax_faces_location_HEAD
type: javax.faces.component.UIPanel@1aa39ff
+id: j_id1658669572_76f81961
type: javax.faces.component.UIOutput@c5be3b
+id: j_id1658669572_76f8191b
type: javax.faces.component.UIOutput@4c5482
+id: j_id694659328_9f867e5
type: javax.faces.component.UIOutput@140584c
+id: j_id1442058466_55f4108a <===============
type: javax.faces.component.UIOutput@1651c96
+id: j_id1442058466_55f41060
type: javax.faces.component.UIOutput@137e38c
+id: j_id1442058466_55f4108a <===============
type: javax.faces.component.UIOutput@3c1178
+id: j_id1442058466_55f41060
type: javax.faces.component.UIOutput@19ee7a8
+id: j_id989982498_3b01ef4a
type: javax.faces.component.UIOutput@17b01e5
+id: j_id419915388_190766fe
type: javax.faces.component.UIOutput@b98506
+id: j_id1960618300_1_33722a1f
type: javax.faces.component.UIOutput@1cc5477
+id: j_id1888761497_709436c2
type: javax.faces.component.UIOutput@1bd6c38
+id: j_id-631738478_25a790f2
type: javax.faces.component.UIOutput@10c0ef9
[att1.html]

Ryan Lubke

On 3/20/09 4:10 PM, Lincoln Baxter, III wrote:
> As of the last nightly (downloaded friday the 20th) Looks like
> component name generation is having some issues... this is a pretty
> plain component tree, but has a duplicate ID? Anyone else getting this?
Please provide details on the view.

Since this is probably related to the new state management changes that
we're working on, you can disable the partial
state saving by adding the context init parameter
javax.faces.PARTIAL_STATE_SAVING with a value of false.
>
> SEVERE: Servlet.service() for servlet default threw exception
> com.ocpsoft.socialpm.exceptions.SiteRuntimeException:
> javax.servlet.ServletException: Component ID j_id1442058466_55f4108a
> has already been found in the view. See below for details.
> +id: j_id1
> type: javax.faces.component.UIViewRoot@198d2cc
>
> +id: javax_faces_location_HEAD
> type: javax.faces.component.UIPanel@1aa39ff
>
> +id: j_id1658669572_76f81961
> type: javax.faces.component.UIOutput@c5be3b
>
> +id: j_id1658669572_76f8191b
> type: javax.faces.component.UIOutput@4c5482
>
> +id: j_id694659328_9f867e5
> type: javax.faces.component.UIOutput@140584c
>
> +id: j_id1442058466_55f4108a <===============
> type: javax.faces.component.UIOutput@1651c96
>
> +id: j_id1442058466_55f41060
> type: javax.faces.component.UIOutput@137e38c
>
> +id: j_id1442058466_55f4108a <===============
> type: javax.faces.component.UIOutput@3c1178
>
> +id: j_id1442058466_55f41060
> type: javax.faces.component.UIOutput@19ee7a8
>
> +id: j_id989982498_3b01ef4a
> type: javax.faces.component.UIOutput@17b01e5
>
> +id: j_id419915388_190766fe
> type: javax.faces.component.UIOutput@b98506
>
> +id: j_id1960618300_1_33722a1f
> type: javax.faces.component.UIOutput@1cc5477
>
> +id: j_id1888761497_709436c2
> type: javax.faces.component.UIOutput@1bd6c38
>
> +id: j_id-631738478_25a790f2
> type: javax.faces.component.UIOutput@10c0ef9
>

[att1.html]

Lincoln Baxter, III

Ok, I can reproduce this now... take a look at the composite component
below.

By deleting the tag, I am able to get proper rendering.

This is a layout component, and is used in several places in the page...
I'm guessing that when the component repeats, it is
always adding itself to the HEAD component again, but not assigning
itself a unique ID.

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:composite="http://java.sun.com/jsf/composite">




default="false" />




style="float: right; position:relative; top:-18px; left: -3px;">
rendered="#{compositeComponent.attrs.collapsible eq 'true'}">
onclick="return collapse(event, '#{compositeComponent.clientId}');"
title="Collapse">




rendered="#{!empty compositeComponent.facets.content}">



[att1.html]

Ryan Lubke

On 3/21/09 7:41 AM, Lincoln Baxter, III wrote:
> Ok, I can reproduce this now... take a look at the composite component
> below.
>
> By deleting the tag, I am able to get proper rendering.
>
> This is a layout component, and is used in several places in the
> page... I'm guessing that when the component
> repeats, it is always adding itself to the HEAD component again, but
> not assigning itself a unique ID.
Yep, this is a known issue. We'll hopefully have a fix next week.
>
>
>
> > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> > xmlns:h="http://java.sun.com/jsf/html"
> xmlns:f="http://java.sun.com/jsf/core"
> xmlns:ui="http://java.sun.com/jsf/facelets"
> xmlns:composite="http://java.sun.com/jsf/composite">
>
>
>
>
> > default="false" />
>
>

>
>
> * *
>
>

>

>


> > style="float: right; position:relative; top:-18px; left: -3px;">
> > rendered="#{compositeComponent.attrs.collapsible eq 'true'}">
> > onclick="return collapse(event, '#{compositeComponent.clientId}');"
> title="Collapse">
>
>

>
>

>

>

>
> > rendered="#{!empty compositeComponent.facets.content}">
>
>

>

>
>
>
>

[att1.html]