You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Balaji Saranathan <ba...@wipro.com> on 2005/08/15 17:52:09 UTC

Displaying Error Messages

Hi,

I'm trying to understand how to display error messages that are
indication of some exception cases in the Backing Bean. 
There is no validation involved, but I would like to show up an error
message telling the user that a "Delete action on the table row " has
failed. 
I use the FacesContext.addMessage - but this takes the clientID as the
argument. Is it always necessary to harcode this id in the Backing Bean?

My code looks like this 
    <h:form id="elementForm">
    	<h:message for="elementTable" showDetail="true"
showSummary="true" errorStyle="color:red" />     	
        <h:dataTable id="elementTable"
		..

And in the handler where the exception is thrown 
      catch (NoObjectFoundException exception)
      {
 
FacesContext.getCurrentInstance().addMessage("elementForm:elementTable",
                     new FacesMessage("The Object does not exist .Unable
to delete the specified row. Please check the \n"
                     + "logs for detailed error message !!!" ));
         return null;
      }

Thanks
Balaji




Confidentiality Notice 

The information contained in this electronic message and any attachments to this message are intended
for the exclusive use of the addressee(s) and may contain confidential or privileged information. If
you are not the intended recipient, please notify the sender at Wipro or Mailadmin@wipro.com immediately
and destroy all copies of this message and any attachments.

Re: Displaying Error Messages

Posted by Mike Kienenberger <mk...@gmail.com>.
To see global (null) messages, you need a component like this on your page

<h:messages globalOnly="true" styleClass="errors" showDetail="true"/>


On 8/15/05, Balaji Saranathan <ba...@wipro.com> wrote:
> 
> Mike,
>  Thanks for your help. Setting it to Null didnt show me the message, but I 
> guess I was erring somewhere. But ofcourse, I found the second approach more 
> cleaner. 
>  Regards
> Bala
>   -----Original Message-----
> *From:* Mike Kienenberger [mailto:mkienenb@gmail.com] 
> *Sent:* Monday, August 15, 2005 12:05 PM
> *To:* MyFaces Discussion; balaji.saranathan@wipro.com
> *Subject:* Re: Displaying Error Messages
> 
> You can either use "null" to specify a global error message, or you can 
> set a binding on your "elementForm:elementTable" so that's it's available 
> as a UIComponent element to your backing bean. Once you've set up a binding, 
> you can get the client id that way.
> 
> <h:dataTable id="elementTable"
> binding="#{page.elementTableUIComponent}" 
> 
> facesContext.addMessage(elementTableUIComponent.getClientId(facesContext),
> new FacesMessage(...
> 
> 
> On 8/15/05, Balaji Saranathan <ba...@wipro.com> wrote: 
> > 
> > Hi, 
> > 
> > I'm trying to understand how to display error messages that are 
> > indication of some exception cases in the Backing Bean. 
> > 
> > There is no validation involved, but I would like to show up an error 
> > message telling the user that a "Delete action on the table row " has 
> > failed. 
> > 
> > I use the FacesContext.addMessage - but this takes the clientID as the 
> > argument. Is it always necessary to harcode this id in the Backing Bean?
> > 
> > My code looks like this 
> >  <h:form id="elementForm"> 
> >  <h:message for="elementTable" showDetail ="true" showSummary= "true" 
> > errorStyle="color:red" /> 
> >  <h :dataTable id= "elementTable" 
> > …… 
> > 
> > And in the handler where the exception is thrown 
> > catch (NoObjectFoundException exception) 
> > { 
> > FacesContext.getCurrentInstance().addMessage("elementForm:elementTable", 
> > new FacesMessage("The Object does not exist .Unable to delete the 
> > specified row. Please check the \n"
> > 
> > + "logs for detailed error message !!!" )); 
> > return null; 
> > } 
> > 
> > Thanks 
> > Balaji 
> >   
> > 
> > Confidentiality Notice 
> > 
> > The information contained in this electronic message and any attachments 
> > to this message are intended
> > for the exclusive use of the addressee(s) and may contain confidential 
> > or privileged information. If
> > you are not the intended recipient, please notify the sender at Wipro or 
> > Mailadmin@wipro.com immediately
> > and destroy all copies of this message and any attachments.
> > 
> 
> 
> 
> Confidentiality Notice 
> 
> The information contained in this electronic message and any attachments 
> to this message are intended
> for the exclusive use of the addressee(s) and may contain confidential or 
> privileged information. If
> you are not the intended recipient, please notify the sender at Wipro or 
> Mailadmin@wipro.com immediately
> and destroy all copies of this message and any attachments.
>

RE: Displaying Error Messages

Posted by Balaji Saranathan <ba...@wipro.com>.
Mike,
 
Thanks for your help. Setting it to Null didnt show me the message, but
I guess I was erring somewhere. But ofcourse, I found the second
approach more cleaner. 
 
Regards
Bala
 
-----Original Message-----
From: Mike Kienenberger [mailto:mkienenb@gmail.com] 
Sent: Monday, August 15, 2005 12:05 PM
To: MyFaces Discussion; balaji.saranathan@wipro.com
Subject: Re: Displaying Error Messages



You can either use "null" to specify a global error message, or you can
set a binding on your "elementForm:elementTable" so that's it's
available as a UIComponent element to your backing bean.   Once you've
set up a binding, you can get the client id that way.

                          <h:dataTable id="elementTable"
                               binding="#{page.elementTableUIComponent}"


 
facesContext.addMessage(elementTableUIComponent.getClientId(facesContext
),
                    new FacesMessage(...



On 8/15/05, Balaji Saranathan <ba...@wipro.com> wrote: 

Hi, 

I'm trying to understand how to display error messages that are
indication of some exception cases in the Backing Bean. 

There is no validation involved, but I would like to show up an error
message telling the user that a "Delete action on the table row " has
failed. 

I use the FacesContext.addMessage - but this takes the clientID as the
argument. Is it always necessary to harcode this id in the Backing Bean?

My code looks like this 
    <h:form id="elementForm"> 
        <h:message for="elementTable" showDetail ="true" showSummary=
"true" errorStyle="color:red" />            
        <h :dataTable id= "elementTable" 
                .. 

And in the handler where the exception is thrown 
      catch (NoObjectFoundException exception) 
      { 
 
FacesContext.getCurrentInstance().addMessage("elementForm:elementTable",

                     new FacesMessage("The Object does not exist .Unable
to delete the specified row. Please check the \n"

                     + "logs for detailed error message !!!" )); 
         return null; 
      } 

Thanks 
Balaji 



Confidentiality Notice 

The information contained in this electronic message and any attachments
to this message are intended
for the exclusive use of the addressee(s) and may contain confidential
or privileged information. If
you are not the intended recipient, please notify the sender at Wipro or
Mailadmin@wipro.com immediately
and destroy all copies of this message and any attachments.
	






Confidentiality Notice 

The information contained in this electronic message and any attachments to this message are intended
for the exclusive use of the addressee(s) and may contain confidential or privileged information. If
you are not the intended recipient, please notify the sender at Wipro or Mailadmin@wipro.com immediately
and destroy all copies of this message and any attachments.

Re: Displaying Error Messages

Posted by Mike Kienenberger <mk...@gmail.com>.
You can either use "null" to specify a global error message, or you can set 
a binding on your "elementForm:elementTable" so that's it's available as a 
UIComponent element to your backing bean. Once you've set up a binding, you 
can get the client id that way.

<h:dataTable id="elementTable"
binding="#{page.elementTableUIComponent}" 

facesContext.addMessage(elementTableUIComponent.getClientId(facesContext),
new FacesMessage(...


On 8/15/05, Balaji Saranathan <ba...@wipro.com> wrote:
> 
> Hi, 
> 
> I'm trying to understand how to display error messages that are indication 
> of some exception cases in the Backing Bean. 
> 
> There is no validation involved, but I would like to show up an error 
> message telling the user that a "Delete action on the table row " has 
> failed. 
> 
> I use the FacesContext.addMessage - but this takes the clientID as the 
> argument. Is it always necessary to harcode this id in the Backing Bean?
> 
> My code looks like this 
>  <h:form id="elementForm"> 
>  <h:message for="elementTable" showDetail="true" showSummary="true" 
> errorStyle="color:red" /> 
>  <h:dataTable id="elementTable" 
> …… 
> 
> And in the handler where the exception is thrown 
> catch (NoObjectFoundException exception) 
> { 
> FacesContext.getCurrentInstance().addMessage("elementForm:elementTable", 
> new FacesMessage("The Object does not exist .Unable to delete the 
> specified row. Please check the \n"
> 
> + "logs for detailed error message !!!" )); 
> return null; 
> } 
> 
> Thanks 
> Balaji 
> 
> 
> Confidentiality Notice 
> 
> The information contained in this electronic message and any attachments 
> to this message are intended
> for the exclusive use of the addressee(s) and may contain confidential or 
> privileged information. If
> you are not the intended recipient, please notify the sender at Wipro or 
> Mailadmin@wipro.com immediately
> and destroy all copies of this message and any attachments.
>