Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

jsf Logical Not

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

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



(Notice the '!')

thank you very much
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
#{} 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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answer! btw the example i mentioned in my other post was just an example.
The point was the Not ;).

 
Saloon Keeper
Posts: 22256
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
For my next trick, I'll need the help of a tiny ad ...
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic