users@javaserverfaces.java.net

Re: I don't understand why I can't use a FacesMessage within a catch statement in a Backing Bean?

From: Ryan Lubke <Ryan.Lubke_at_Sun.COM>
Date: Wed, 21 Mar 2007 09:34:37 -0700

Hi Todd,

Any follow up on this?

Todd Patrick wrote:
> Ryan:
>
> In your example, did you use:
>
> FacesContext.renderResponse();
>
> after your FacesMessage and within the catch statement or outside the
> catch statement?
>
> Thanks,
>
> --Todd
>
>
> -----Original Message-----
> From: Ryan.Lubke_at_Sun.COM [mailto:Ryan.Lubke_at_Sun.COM]
> Sent: Friday, March 16, 2007 12:15 AM
> To: users_at_javaserverfaces.dev.java.net
> Subject: Re: I don't understand why I can't use a FacesMessage within a
> catch statement in a Backing Bean?
>
> Todd Patrick wrote:
>
>> What I have is the following:
>>
>> <h:commandButton id="freesearchBtn"
>> value="#{common.labelBtnSearch}"
>> actionListener="#{tbrowser.doFreeFormSearch}"/>
>>
>> Calling:
>>
>> public void doFreeFormSearch(ActionEvent event) {
>> FacesContext facesContext = FacesContext.getCurrentInstance();
>> FacesMessage message = new FacesMessage();
>>
>> ...
>>
>> try {
>>
>> ...
>>
>> } catch (MyException e) {
>> message.setSeverity(FacesMessage.SEVERITY_ERROR);
>> message.setSummary("No results found.");
>>
>> facesContext.addMessage(null, message);
>> facesContext.renderResponse();
>>
>> logger.error("My Exception:", e);
>>
>>
>> I don't have an action on the h:commandButton.
>>
>> I just don't understand that when I debug the backing bean, it steps
>> into the catch statement, nothing errors... no server.log messages or
>> anything.
>>
>> But the <h:messages/> doesn't render.
>>
>>
> I'm going to agree with Mike on this. It would be useful to have a
> repro.
> As a sanity check I created a simple repro based on the info above and
> all works fine.
>
>
>> Thanks,
>>
>> --Todd
>>
>> -----Original Message-----
>> From: Michael Youngstrom [mailto:youngm_at_gmail.com]
>> Sent: Wednesday, March 14, 2007 6:16 PM
>> To: users_at_javaserverfaces.dev.java.net
>> Subject: Re: Re: I don't understand why I can't use a FacesMessage
>> within a catch statement in a Backing Bean?
>>
>> So by "redisplaying the page" you're saying you either don't have an
>> action attribute on your command component or the action you are
>> specifying is mapped to a navigation case without a <redirect/> tag on
>>
>
>
>> it.
>>
>> If you're not redirecting then I'm out of ideas. :) Perhaps you can
>> attach as simple .war that duplicates the problem?
>>
>> Mike
>>
>> On 3/14/07, Todd Patrick <Todd.Patrick_at_dtn.com> wrote:
>>
>>
>>> No.
>>>
>>> I am redisplaying the page.
>>>
>>> Thanks,
>>>
>>> --Todd
>>>
>>> -----Original Message-----
>>> From: Michael Youngstrom [mailto:youngm_at_gmail.com]
>>> Sent: Wednesday, March 14, 2007 12:35 PM
>>> To: users_at_javaserverfaces.dev.java.net
>>> Subject: Re: I don't understand why I can't use a FacesMessage within
>>>
>
>
>>> a catch statement in a Backing Bean?
>>>
>>> Are you doing a redirect when rendering the new page by chance?
>>>
>>> On 3/14/07, Todd Patrick <Todd.Patrick_at_dtn.com> wrote:
>>>
>>>
>>>> JSF 1.2_04
>>>> Sun Java System Application Server 9.0_01
>>>>
>>>> I don't understand why I can't use a FacesMessage within a catch
>>>> statement in a Backing Bean?
>>>>
>>>> For example, in an event:
>>>>
>>>> public void doFreeFormSearch(ActionEvent event) {
>>>> FacesContext facesContext =
>>>>
>>>>
>> FacesContext.getCurrentInstance();
>>
>>
>>>> FacesMessage message = new FacesMessage();
>>>>
>>>> ...
>>>>
>>>> try {
>>>>
>>>> ...
>>>>
>>>> } catch (MyException e) {
>>>> message.setSeverity(FacesMessage.SEVERITY_ERROR);
>>>> message.setSummary("No results found.");
>>>>
>>>> facesContext.addMessage(null, message);
>>>> facesContext.renderResponse();
>>>>
>>>> logger.error("My Exception:", e);
>>>>
>>>>
>>>> On my JSP page, I have:
>>>>
>>>> <h:messages/>
>>>>
>>>> When I catch MyException, the error message *is* written to my
>>>> server.log file, but the h:messages component is never rendered?
>>>>
>>>> I step through this in Netbeans 5.5 and the FacesMessage is added to
>>>>
>>>>
>>
>>
>>>> the FacesContext.
>>>>
>>>> How do I use FacesMessage correctly with a try/catch statement?
>>>>
>>>> (I've fought this for over a day now.)
>>>>
>>>> Thanks,
>>>>
>>>> --Todd
>>>>
>>>> -----------------------------------------
>>>> NOTICE: This email message is for the sole use of the intended
>>>> recipient(s) and may contain confidential and privileged
>>>>
>>>>
>> information.
>>
>>
>>>> Any unauthorized use, disclosure or distribution is prohibited. If
>>>> you
>>>>
>>>> are not the intended recipient, please contact the sender by reply
>>>> email and destroy all copies of the original message.
>>>>
>>>>
>>>> --------------------------------------------------------------------
>>>> - To unsubscribe, e-mail:
>>>> users-unsubscribe_at_javaserverfaces.dev.java.net
>>>> For additional commands, e-mail:
>>>> users-help_at_javaserverfaces.dev.java.net
>>>>
>>>>
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:
>>> users-unsubscribe_at_javaserverfaces.dev.java.net
>>> For additional commands, e-mail:
>>> users-help_at_javaserverfaces.dev.java.net
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:
>>> users-unsubscribe_at_javaserverfaces.dev.java.net
>>> For additional commands, e-mail:
>>> users-help_at_javaserverfaces.dev.java.net
>>>
>>>
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_javaserverfaces.dev.java.net
>> For additional commands, e-mail:
>> users-help_at_javaserverfaces.dev.java.net
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_javaserverfaces.dev.java.net
>> For additional commands, e-mail:
>> users-help_at_javaserverfaces.dev.java.net
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_javaserverfaces.dev.java.net
> For additional commands, e-mail: users-help_at_javaserverfaces.dev.java.net
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_javaserverfaces.dev.java.net
> For additional commands, e-mail: users-help_at_javaserverfaces.dev.java.net
>
>