I am working in JSF 2 with Primefaces 3.4 and I found an example where '==' in my xhtml does not behave like '==' in Java. I could not find details for '==' operator in Java EE 6 documentation. What does it exactly do? Is there an equivalent of Java '==' for Objects in EL?
Asked
Active
Viewed 1,067 times
0
-
1Yes, it is. You can also use `eq` instead of `==` in EL. – Luiggi Mendoza Oct 21 '13 at 15:42
-
@LuiggiMendoza: Yes, it is what? There were two options given. – recursive Oct 21 '13 at 15:42
-
1From EL, using `==` is **the same of** using `==` for primitives and `equals` for objects, like `String`s. Did you at least tried it? – Luiggi Mendoza Oct 21 '13 at 15:43
-
Also, this is EL, it is not just for Java EE nor JSF, it also works in EL `${}` used in a servlet container like Tomcat. – Luiggi Mendoza Oct 21 '13 at 15:44
-
1@Luiggi Is there an equivalent to `==` for object references in EL? – Sotirios Delimanolis Oct 21 '13 at 15:44
-
Sotirios- this is exactly what I was after Thank you Luiggi for extra clarifications. – bjedrzejewski Oct 21 '13 at 15:45
-
1@SotiriosDelimanolis AFAIK no, and if your class doesn't implement `equals` it will use default `Object#equals` that ends using `==`. – Luiggi Mendoza Oct 21 '13 at 15:46
-
http://www.roseindia.net/java/javaee6/ExpressionLanguage.shtml – PM 77-1 Oct 21 '13 at 15:46
-
Edited the question to more reflect my problem. – bjedrzejewski Oct 21 '13 at 15:47
-
@PM77-1 IMO roseindia.net teaches JSF and related technologies in the wrong way. If you want to refer to a good resource about EL, use [StackOverflow EL's wiki](http://stackoverflow.com/tags/el/info) instead. – Luiggi Mendoza Oct 21 '13 at 15:48
-
@user2511414 AFAIK `is` is not an EL keyword nor a valid operator. Refer to [EL Operators](http://docs.oracle.com/javaee/7/tutorial/doc/jsf-el006.htm#BNAIK). – Luiggi Mendoza Oct 21 '13 at 15:52
-
@LuiggiMendoza Oh sorry, I just got it wrong with another tag libraries, sorry, thanks for notify, good catch :) – Oct 21 '13 at 16:04
-
This is an [XY problem](http://meta.stackexchange.com/q/66377/166890). "'==' in my xhtml does not behave like '==' in Java" isn't true unless your expectations are incorrect. I suggest you solve *that* problem. – user207421 Oct 22 '13 at 00:45
1 Answers
2
Is there an equivalent of Java '==' for Objects in EL?
Looks like it is not, but you don't really need it. EL ==
(and eq
) will use the equals
method when comparing object references, and it already supports null
comparison. If your class happens to not override equals
, then it will use Object#equals
that ends using Java ==
for equality check.
If your class happens to override equals
method, make sure to write a good implementation. As example:
public boolean equals(Object o) {
if (o == null) {
return false;
}
if (this == o) {
return true;
}
if (...) {
//add here the rest of the equals implementation...
}
return false;
}
More info:

Luiggi Mendoza
- 85,076
- 16
- 154
- 332
-
I know I can use equals, but my question is to bypass it and use '==' instead. If this is not possible, then I will wait a bit more (in case someone has a genius answer) and accept your answer. – bjedrzejewski Oct 21 '13 at 16:01
-
@jedrus07 maybe if your post your actual problem you could get a more accurate answer. – Luiggi Mendoza Oct 21 '13 at 16:05
-
@LuiggiMendoza Mendoza The **link** *Java EE tutorial: Expression Language: Operators* is **broken**. Please update it. – OO7 May 14 '15 at 13:25
-
@OO7 link updated. Thanks. I recommend you to update links whenever you can, not only here but in other Q/As as well. – Luiggi Mendoza May 14 '15 at 14:38
-