You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Madhav Bhargava <Ma...@infosys.com> on 2010/01/20 14:15:35 UTC

FacesMessage with severity ERROR do not prevent calling an action method

Hi,

I am using myfaces 1.1, icefaces 1.8.1 on WAS 6.0

The controller (backing bean) action methods handle RuntimeException from the service layer. Depending on the exception an exception handler will put an appropriate message into FacesContext.
For that I have created a utility method:

public static void putMessage(String key, Severity severity,
                                String summary, String detail) {
                FacesContext.getCurrentInstance().addMessage(key,
                                                new FacesMessage(severity, summary, detail));
}

In the controller this method is used to put messages. When the page is displayed the messages appear properly. However when a user clicks on a commandButton then the control goes to the action method bound to the commandButton. This should not happen because there are FacesMessages with FacesMessage.SEVERITY_ERROR. I checked immediate="true" has not been set on the commandButton component.

Is my understanding not correct that if there are FacesMessages with Severity = SEVERITY_ERROR in the FacesContext then the invoke application phase will not happen and the control would come back to the current page in error?

Regards,
Madhav

**************** CAUTION - Disclaimer *****************
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely 
for the use of the addressee(s). If you are not the intended recipient, please 
notify the sender by e-mail and delete the original message. Further, you are not 
to copy, disclose, or distribute this e-mail or its contents to any other person and 
any such actions are unlawful. This e-mail may contain viruses. Infosys has taken 
every reasonable precaution to minimize this risk, but is not liable for any damage 
you may sustain as a result of any virus in this e-mail. You should carry out your 
own virus checks before opening the e-mail or attachment. Infosys reserves the 
right to monitor and review the content of all messages sent to or from this e-mail 
address. Messages sent to or from this e-mail address may be stored on the 
Infosys e-mail system.
***INFOSYS******** End of Disclaimer ********INFOSYS***

RE: FacesMessage with severity ERROR do not prevent calling an action method

Posted by Madhav Bhargava <Ma...@infosys.com>.
Hi Volkar,

Thanks for your response. I will add that to the method so that it does not have to be explicitly done by the developers in their action methods.

>From: weber.volker@googlemail.com [mailto:weber.volker@googlemail.com] On Behalf Of Volker Weber
>
>Hi Madhav,
>
>the livecycle did not depend on messages in the context. To prevent
>executing actions and direct skip to renderPhase you need to call
>
>FacesContext.getCurrentInstance().renderResponse();
>
>e.g. in your putMessage() method.
>
>
>Regards,
>    Volker
>
2010/1/20 Madhav Bhargava <Ma...@infosys.com>:
> Hi,
>
> I am using myfaces 1.1, icefaces 1.8.1 on WAS 6.0
>
> The controller (backing bean) action methods handle RuntimeException from the service layer. Depending on the exception an exception handler will put an appropriate message into FacesContext.
> For that I have created a utility method:
>
> public static void putMessage(String key, Severity severity,
>                                String summary, String detail) {
>                FacesContext.getCurrentInstance().addMessage(key,
>                                                new FacesMessage(severity, summary, detail));
> }
>
> In the controller this method is used to put messages. When the page is displayed the messages appear properly. However when a user clicks on a commandButton then the control goes to the action method bound to the commandButton. This should not happen because there are FacesMessages with FacesMessage.SEVERITY_ERROR. I checked immediate="true" has not been set on the commandButton component.
>
> Is my understanding not correct that if there are FacesMessages with Severity = SEVERITY_ERROR in the FacesContext then the invoke application phase will not happen and the control would come back to the current page in error?
>
> Regards,
> Madhav
>
> **************** CAUTION - Disclaimer *****************
> This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely
> for the use of the addressee(s). If you are not the intended recipient, please
> notify the sender by e-mail and delete the original message. Further, you are not
> to copy, disclose, or distribute this e-mail or its contents to any other person and
> any such actions are unlawful. This e-mail may contain viruses. Infosys has taken
> every reasonable precaution to minimize this risk, but is not liable for any damage
> you may sustain as a result of any virus in this e-mail. You should carry out your
> own virus checks before opening the e-mail or attachment. Infosys reserves the
> right to monitor and review the content of all messages sent to or from this e-mail
> address. Messages sent to or from this e-mail address may be stored on the
> Infosys e-mail system.
> ***INFOSYS******** End of Disclaimer ********INFOSYS***
>



-- 
inexso - information exchange solutions GmbH
Bismarckstraße 13      | 26122 Oldenburg
Tel.: +49 441 4082 356 |
FAX:  +49 441 4082 355 | www.inexso.de

Re: FacesMessage with severity ERROR do not prevent calling an action method

Posted by Volker Weber <v....@inexso.de>.
Hi Madhav,

the livecycle did not depend on messages in the context. To prevent
executing actions and direct skip to renderPhase you need to call

FacesContext.getCurrentInstance().renderResponse();

e.g. in your putMessage() method.


Regards,
    Volker

2010/1/20 Madhav Bhargava <Ma...@infosys.com>:
> Hi,
>
> I am using myfaces 1.1, icefaces 1.8.1 on WAS 6.0
>
> The controller (backing bean) action methods handle RuntimeException from the service layer. Depending on the exception an exception handler will put an appropriate message into FacesContext.
> For that I have created a utility method:
>
> public static void putMessage(String key, Severity severity,
>                                String summary, String detail) {
>                FacesContext.getCurrentInstance().addMessage(key,
>                                                new FacesMessage(severity, summary, detail));
> }
>
> In the controller this method is used to put messages. When the page is displayed the messages appear properly. However when a user clicks on a commandButton then the control goes to the action method bound to the commandButton. This should not happen because there are FacesMessages with FacesMessage.SEVERITY_ERROR. I checked immediate="true" has not been set on the commandButton component.
>
> Is my understanding not correct that if there are FacesMessages with Severity = SEVERITY_ERROR in the FacesContext then the invoke application phase will not happen and the control would come back to the current page in error?
>
> Regards,
> Madhav
>
> **************** CAUTION - Disclaimer *****************
> This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely
> for the use of the addressee(s). If you are not the intended recipient, please
> notify the sender by e-mail and delete the original message. Further, you are not
> to copy, disclose, or distribute this e-mail or its contents to any other person and
> any such actions are unlawful. This e-mail may contain viruses. Infosys has taken
> every reasonable precaution to minimize this risk, but is not liable for any damage
> you may sustain as a result of any virus in this e-mail. You should carry out your
> own virus checks before opening the e-mail or attachment. Infosys reserves the
> right to monitor and review the content of all messages sent to or from this e-mail
> address. Messages sent to or from this e-mail address may be stored on the
> Infosys e-mail system.
> ***INFOSYS******** End of Disclaimer ********INFOSYS***
>



-- 
inexso - information exchange solutions GmbH
Bismarckstraße 13      | 26122 Oldenburg
Tel.: +49 441 4082 356 |
FAX:  +49 441 4082 355 | www.inexso.de

RE: FacesMessage with severity ERROR do not prevent calling an action method

Posted by Madhav Bhargava <Ma...@infosys.com>.
True, you are right.
The problem was that the first request goes as an AJAX request submitting on a part of the form. If there are errors, messages are shown. Now the user clicks on any other control which submits the rest of the page barring the one which was previously submitted. That caused the action to be executed as expected because that part of the page is never submitted.

Sorry for the confusion and thanks a lot for your response.

Regards,
Madhav

>From: Michael Kurz [mailto:michi.kurz@gmx.at] 
>Sent: Wednesday, January 20, 2010 7:05 PM
>
>Hi,
>
>for clearification: does the click on the command button take place 
>AFTER the page with the error messages was rendered? Because if it is 
>so, this is the expected behavior. The messages in the FacesContext are 
>only available for the current request, which is the one producing the 
>error. If you click on a command button on this page a new request with 
>a new FacesContext is started. Unless this produces the same error the 
>messages will be gone.
>
>regards
>Michael
>
>Madhav Bhargava schrieb:
> Hi,
> 
> I am using myfaces 1.1, icefaces 1.8.1 on WAS 6.0
> 
> The controller (backing bean) action methods handle RuntimeException from the service layer. Depending on the exception an exception handler will put an appropriate message into FacesContext.
> For that I have created a utility method:
> 
> public static void putMessage(String key, Severity severity,
>                                 String summary, String detail) {
>                 FacesContext.getCurrentInstance().addMessage(key,
>                                                 new FacesMessage(severity, summary, detail));
> }
> 
> In the controller this method is used to put messages. When the page is displayed the messages appear properly. However when a user clicks on a commandButton then the control goes to the action method bound to the commandButton. This should not happen because there are FacesMessages with FacesMessage.SEVERITY_ERROR. I checked immediate="true" has not been set on the commandButton component.
> 
> Is my understanding not correct that if there are FacesMessages with Severity = SEVERITY_ERROR in the FacesContext then the invoke application phase will not happen and the control would come back to the current page in error?
> 
> Regards,
> Madhav
> 
> **************** CAUTION - Disclaimer *****************
> This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely 
> for the use of the addressee(s). If you are not the intended recipient, please 
> notify the sender by e-mail and delete the original message. Further, you are not 
> to copy, disclose, or distribute this e-mail or its contents to any other person and 
> any such actions are unlawful. This e-mail may contain viruses. Infosys has taken 
> every reasonable precaution to minimize this risk, but is not liable for any damage 
> you may sustain as a result of any virus in this e-mail. You should carry out your 
> own virus checks before opening the e-mail or attachment. Infosys reserves the 
> right to monitor and review the content of all messages sent to or from this e-mail 
> address. Messages sent to or from this e-mail address may be stored on the 
> Infosys e-mail system.
> ***INFOSYS******** End of Disclaimer ********INFOSYS***
> 


Re: FacesMessage with severity ERROR do not prevent calling an action method

Posted by Michael Kurz <mi...@gmx.at>.
Hi,

for clearification: does the click on the command button take place 
AFTER the page with the error messages was rendered? Because if it is 
so, this is the expected behavior. The messages in the FacesContext are 
only available for the current request, which is the one producing the 
error. If you click on a command button on this page a new request with 
a new FacesContext is started. Unless this produces the same error the 
messages will be gone.

regards
Michael

Madhav Bhargava schrieb:
> Hi,
> 
> I am using myfaces 1.1, icefaces 1.8.1 on WAS 6.0
> 
> The controller (backing bean) action methods handle RuntimeException from the service layer. Depending on the exception an exception handler will put an appropriate message into FacesContext.
> For that I have created a utility method:
> 
> public static void putMessage(String key, Severity severity,
>                                 String summary, String detail) {
>                 FacesContext.getCurrentInstance().addMessage(key,
>                                                 new FacesMessage(severity, summary, detail));
> }
> 
> In the controller this method is used to put messages. When the page is displayed the messages appear properly. However when a user clicks on a commandButton then the control goes to the action method bound to the commandButton. This should not happen because there are FacesMessages with FacesMessage.SEVERITY_ERROR. I checked immediate="true" has not been set on the commandButton component.
> 
> Is my understanding not correct that if there are FacesMessages with Severity = SEVERITY_ERROR in the FacesContext then the invoke application phase will not happen and the control would come back to the current page in error?
> 
> Regards,
> Madhav
> 
> **************** CAUTION - Disclaimer *****************
> This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely 
> for the use of the addressee(s). If you are not the intended recipient, please 
> notify the sender by e-mail and delete the original message. Further, you are not 
> to copy, disclose, or distribute this e-mail or its contents to any other person and 
> any such actions are unlawful. This e-mail may contain viruses. Infosys has taken 
> every reasonable precaution to minimize this risk, but is not liable for any damage 
> you may sustain as a result of any virus in this e-mail. You should carry out your 
> own virus checks before opening the e-mail or attachment. Infosys reserves the 
> right to monitor and review the content of all messages sent to or from this e-mail 
> address. Messages sent to or from this e-mail address may be stored on the 
> Infosys e-mail system.
> ***INFOSYS******** End of Disclaimer ********INFOSYS***
>