Well, the name of the game is to create JavaScript. If the javascript is in a JavaScript file, then it's already javascript and therefore usable "as is".
But a JSF xhtml View is an XML file. And, like I said, XML has a constraint on the "5 magic characters", because if you coded them directly, the XML parsers wouldn't be able to tell XML markup from data within the markup. For example:
Question: is the first double-quote the
string terminator, or is the second double-quote the string terminator? OK, so that's easy to tell. For you. The CodeRaqnch syntax colorer obviously doesn't thing it's so simple. What if you have a whole FILE full of those puppies? Stack enough of them together and they start being readable in multiple (ambiguous) ways. So the proper usage is via the XML double-quote entity:
That way, no guesswork is involved. Since the Ampersand is the escape character, the Ampersand itself must be escaped, so that you don't end up trying to puzzle out stuff like the following:
And so forth.
Now, in some cases, the parser will cut you some slack. For example, you can usually use an apostrophe "as is" within quotes without having to resort to its XML entity form. But if there's a chance of confusion, you won't be allowed that. And it's never wrong to do it anyway.
Since "&" is the escape character, you're pretty much required to use its entity form at all times.
As for the use of the
word "and" instead of "&&", like I said, I don't believe that "and" is valid javascript. The confusion there is that "and"
is valid EL, and if you don't pay attention to context, you can confuse EL with javascript, since they're both java-like languages.
In JSF, however, the giveaway is that EL is delimited using the "#{}" construct.
What makes this even MORE fun is that you can have EL embedded within JavaScript! And I have, in fact. Basically, EL becomes a "macro language" at that point, and the results of evaluating the EL subexpression(s) replaces the EL to form an ordinary text string, which is then interpreted as JavaScript.
And no, "a #{&&} b" isn't legal. The double-ampersand is going to be interpreted as a binary operator, and there's no left and right terms of the expression that it would be applied to. "a" and "b" are outside the EL context.