This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSF and the fly likes jsf Logical Not Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "jsf Logical Not" Watch "jsf Logical Not" New topic
Author

jsf Logical Not

JayJay Capra
Greenhorn

Joined: Jul 13, 2011
Posts: 9
Hi ,

How can i negate a propertie of my managed bean.
Something like this



(Notice the '!')

thank you very much
Krystian Gor
Ranch Hand

Joined: Jan 11, 2011
Posts: 30
#{} is an expression of Expression Language.
Goggle to find out that EL is not a part of JSF specification. It's still part of JSP 2.1 specificaton(but its specification will be separated as it can be used not only with JSP).
So I download this part of JSP 2.1 specificaton: jsp-2_1-fr-spec-el.pdf.
When I open pdf I search for "operators". I scan area of the first occurrence to find a section called 1.9 Logical Operators.
I scroll to desired page and read:
1.9 Logical Operators
The logical operators are:
&& and and
|| and or
! and not
The evaluation of logical operators is described in the following sections.

Seems like exclamation mark is fine
Krystian Gor
Ranch Hand

Joined: Jan 11, 2011
Posts: 30
As I still have this pdf document open and I'm sure the mistake I made must be something basic I start to read section 1.2 EL Expressions.
It turns out that there are two types of expressions.
An EL expression is parsed as either a value expression or a method expression. A value
expression refers to a value, whereas a method expression refers to a method on an
object.

We don't need method expression as you want your expression to return a value: true or false.
So I read more and find:
Faces (...) component model that requires expressions to represent more than just rvalues. It needs expressions to represent
references to data structures

Seems like you don't have to put your method name isUser. You only have to reference data structure. Your field name(data structure) is user, so your expression to access this field requires only a name of this field: user instead of isUser.
Try using this expression:

Should work.
I hope you're aware of few more mistakes in your code example as h:form tag doesn't have a render attribute. This attribute is rendered.
Another mistake is lack of quotes around your EL expression "".
So, correct code is:
<h:form rendered="#{!beanUser.user}" >

Good luck!
JayJay Capra
Greenhorn

Joined: Jul 13, 2011
Posts: 9
Thanks for your answer! btw the example i mentioned in my other post was just an example.
The point was the Not ;).

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

JSF EL property references follow standard POJO javabean rules. So if you declare a property reference such as "bean.isUser", the EL processor is going to attempt to invoke the following method:


That's right. Because it's a property, the first character of the name is folder to uppercase and then the actual method name is synthesised by prefixing with "get" for non-boolean properties or "is" for boolean properties. I think "get " works for booleans, as well, but it's not a good idea.

One peeve I have about Java over languages such as C is that I can't do macro definitions. The logical "!" operator is very small and easy to miss, so in C, I used to alias it to "NOT".

Java itself doesn't allow that, but EL has additional operator forms, which means that instead of "!bean.user", you can code like this:


Customer surveys are for companies who didn't pay proper attention to begin with.
 
Don't get me started about those stupid light bulbs.
 
subject: jsf Logical Not