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());
}

