Bansi,

Usually, you would just add a new FacesMessage to the FacesContext like so:

        facesContext.addMessage(null,
                              new FacesMessage(FacesMessage.SEVERITY_ERROR,
                              "Duplicate id found", "detailed
description...."));

(I'm assuming that your FacesUtils class has a addErrorMessage() method
which you could use instead.)

And then display it in your error page like so:

        <h:messages globalOnly="true"/>

What does ex.getMessages() return?

> -----Original Message-----
> From: bansi [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, June 05, 2007 4:01 PM
> To: [email protected]
> Subject: RE: Exception Handling using JSF/MyFaces and Spring
> 
> 
> Thanks Kito for the suggestion. I would like to do something like this
> ...
> public String createManufacturer() {
> 
>       try{
>               manufManager.createManufacturer(namsManufacturer);
>               FacesUtils.addInfoMessage("save", "Manufacturer",
> namsManufacturer.getName());
> 
> 
>       }catch(DuplicateManufacturerIdException ex) {
> 
>               System.out.println(" catching
> DuplicateManufacturerIdException In Backing
> Bean");
> 
> FacesContext.getCurrentInstance().getExternalContext().getRequestMap().
> put("errors",
> ex.getMessages());
>               return "error";
> 
>     }
>       catch(Exception e) {
>         logger.warn(e.getMessage());
>     }
> 
>       return "success";
> 
>   }
> Let say if i have "error" defined in navigation-rule to print errors on
> different or same page. How should i iterate thru the meesage list  and
> print them on browser. I know its available in RequestMap.
> A code snippet will be highly appreciated
> 
> Regards
> Bansi
> 
> 
> Kito D. Mann wrote:
> >
> >> -----Original Message-----
> >> From: bansi [mailto:[EMAIL PROTECTED]
> >> Sent: Friday, June 01, 2007 1:29 PM
> >> To: [email protected]
> >> Subject: Exception Handling using JSF/MyFaces and Spring
> >>
> >>
> >> I am using JSF MyFaces, Spring, Hibernate .
> >> Any pointers/suggestions on how to  modify  below code to display
> >> user-friendly messages onto browser incase an exception occured in
> JSF
> >> Backing Bean or  Spring Bean will be highly appreciated
> >
> > Your code looks fine -- if you want the user to see a message on the
> same
> > page, the simplest thing to do is just add an error message to the
> > FacesContext and return null rather than throwing a FacesException.
> >
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > Kito D. Mann - Author, JavaServer Faces in Action
> > http://www.virtua.com - JSF/Java EE consulting, training, and
> mentoring
> > http://www.JSFCentral.com - JavaServer Faces FAQ, news, and info
> >
> > * Sign up for the JSF Central newsletter!
> > http://oi.vresp.com/?fid=ac048d0e17 *
> >
> >
> >>
> >> JSF Backing Bean:
> >>
> >> public List getDeviceTypeList(){
> >> try {
> >> deviceTypes = deviceTypeManager.getDeviceTypeList(); // method call
> to
> >> Spring Bean
> >> return deviceTypeSelectItems;
> >> } catch (Exception e) {
> >> String msg = "Could not retrieve DeviceType List " + e.toString();
> >> this.logger.error(msg);
> >> throw new FacesException(msg);
> >> }
> >> }
> >>
> >> Spring Bean:
> >>
> >> public List getDeviceTypeList() throws BaseException{
> >> List deviceTypeList = null;
> >> try{
> >> deviceTypeList = deviceTypeDao.findByNamedQuery("findDeviceTypes");
> //
> >> database call
> >> } catch (NullPointerException ne) {
> >> String msg = "Could not retrieve data from Database " +
> >> ne.getMessage();
> >> this.logger.error(msg, ne);
> >> } catch (Exception e) {
> >> String msg = "Could not retrieve data from Database " +
> e.toString();
> >> this.logger.error(msg, e);
> >> throw new BaseException(msg, e);
> >> }
> >> return deviceTypeList;
> >> }
> >>
> >> Is it true that Spring advocates against having  signature of
> business
> >> methods throws exception ???
> >> For example in my case it is public List getDeviceTypeList() throws
> >> BaseException
> >>
> >> Regards
> >> Bansi
> >>
> >>
> >>
> >> --
> >> View this message in context: http://www.nabble.com/Exception-
> Handling-
> >> using-JSF-MyFaces-and-Spring-tf3853562.html#a10917207
> >> Sent from the MyFaces - Users mailing list archive at Nabble.com.
> >
> >
> >
> 
> --
> View this message in context: http://www.nabble.com/Exception-Handling-
> using-JSF-MyFaces-and-Spring-tf3853562.html#a10977673
> Sent from the MyFaces - Users mailing list archive at Nabble.com.

Reply via email to