On Mon, Feb 16, 2009 at 2:48 PM, Simon Kitching <[email protected]>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?
>
> 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
> --
> -- Emails in "mixed" posting style will be ignored
> -- (http://en.wikipedia.org/wiki/Posting_style)
>
This might be an option i can consider at the moment if i do not want to
write a custom EL resolver. Also as matthias pointed out that method
invocations are going to be a part of JSF EL soon.
Thanks for your quick response. I will try it out and let you know if that
works for me. In case i come out with a cleaner solutions then i will post
it here.
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