On Mon, Feb 16, 2009 at 2:48 PM, Simon Kitching 
<skitch...@apache.org<mailto:skitch...@apache.org>> wrote:
Madhav Bhargava schrieb:
> Hi All,
>
>
>
> I have a requirement wherein I have to disable UI components based on
> whether there are any error messages in the Message Queue (t:messages).
>
> facesContext is an implicit object so I thought of using it like -
> #{facesContext.getMessages.hasNext} However when it was not working
> because you can only specify properties of a class and JSF variable and
> property resolver will then internally try and call the getter/setter of
> that property.
>
>
>
> I find that rather limiting because I do not find the need to define a
> class level property when all I need is to process and output a Boolean.
> Is there any way apart from overriding the
> PropertyResolver/VariableResolver?
>Simon wrote:
>No, EL does not allow "method calls". It only allows reading/writing
>properties.
>
>However isn't this enough for what you want to do?
>
>You could create a simple class:
>public class MessageChecker {
>   public boolean isMessagePresent() {
>     return FacesContext.currentInstance().getMessages().hasNext();
>   }
> }
>
>Then register this class as an app-scope managed bean.
>
>JSF components can then do
> disabled="#{messageChecker.messagePresent}"
>
>Yes this means creating a trivial class, and having an instance of it in
>memory in order to call a static method from the JSF components. This
>could be considered ugly. But on the other hand, the JSF pages are now
>much better isolated from the details of the implementation.
>
>Regards,
>Simon

Your solution will not work for messages which get added to the FacesContext 
during the validation phase. Method isMessagePresent() will not be called. That 
is the reason I was looking at accessing the messages as an EL expression.
If there is a validation/conversion exception thrown then it will directly go 
to the render response phase after completing the validation phase.

I will try and use a scriptlet to get access to messages and see if that is 
going to work. Not the best way of doing things but I will have to live with 
that as of now.

Thanks for your response Simon.

Regards,
Madhav

--
When I tell the truth, it is not for the sake of convincing those who do not 
know it, but for the sake of defending those that do

**************** 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***

Reply via email to