Error handling in overridden methods in AbstractPageBean

Hi,

I'm writing a small app in JSF. One of the pages populates a bunch of text fields from an XML file whose name is passed into the app as an initialization parameter. The purpose of the page is to allow editing of the fields.

It seemed that the prerender() method was the right place to initialize the fields in the form. I have an application-scoped bean trying to open the XML file. I don't want the app to barf on initialization if the file doesn't exist, because the application contains the logic to create the file. So it just sets the appropriate forward target ("file does not exist" page, or maybe XML parse error) and lets the pages that use those bean properties decide when and if they need to display the initialization error page.

I would like to throw an exception from the prerender() method in my page, and have the error handling specified in web.xml. The problem, of course, is that I can't throw my own exception from prerender().

So, have I got the wrong place to initialize my form, or do I have to throw a javax.faces.FacesException, or have I got this whole error-handling thing wrong?

Any advice would be gratefully received.

Many thanks.

Regards,

Mike

publicvoid prerender(){

// Get ApplicationBean1 to forward the request if we fail to

// initialize properly.

ApplicationBean1 ab1 = getApplicationBean1();

HttpServletRequest req = (HttpServletRequest) this.getFacesContext().

getExternalContext().

getRequest();

HttpServletResponse res = (HttpServletResponse) this.getFacesContext().

getExternalContext().

getResponse();

if(!ab1.isInitialized()){

//The initialization code for ApplicationBean1() sets the

//target when it detects an error and then forwards the

//request to that target upon invocation of the forwardRequest

//method

ab1.forwardRequest(req,res);

}

// These are the input components

tfClonebase.setValue(ab1.getClonebase());

tfDhcpdconf.setValue(ab1.getDhcpdconf());

tfNamedrev.setValue(ab1.getNamedrev());

tfNamedzone.setValue(ab1.getNamedzone());

tfPxelinux.setValue(ab1.getPxelinux());

tfXmldir.setValue(ab1.getXmlDir());

}

[2701 byte] By [but.heda] at [2007-11-27 9:36:13]
# 1
I am not familiar with the prerender() method, perhaps you can give a little more background?
RaymondDeCampoa at 2007-7-12 23:04:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
It's a method of AbstractPageBean, which is part of the webuijsf components as is in Sun Java Studio Creator.Also see http://developers.sun.com/docs/jscreator/apis/jsfcl/com/sun/jsfcl/app/AbstractPageBean.htmlI'm also not familair with it however.
BalusCa at 2007-7-12 23:04:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Well, I'm certainly no expert, but prerender() is called, as you might expect, just before rendering takes place (but only if the page will actually be rendered). This means it won't be called for a page that handled a postback but then navigated to a different page. Good place to handle initializations that happen before rendering.

So my thinking was that I could initialize stuff before there's anything in the response, making it easier to bail out if something goes bad.

But I really can't work out the right way to bail out: I can't throw my own exception because the prerender() is overridden from AbstractPageBean. So I suppose I could create a MikesBadInitException e and throw it inside a new javax.faces.FacesException(e). But I'd like to specify an error-page in my web.xml for MikesBadInitException, and don't want to handle all javax.faces.FacesExceptions, if you get my drift.

but.heda at 2007-7-12 23:04:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...