This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I'm not seeing it. I know, and people who I trust tell me that EL is modern and scriptlets are bad, evil and should be banned.
While scriptlettes may be a bit ugly, I'm not seeing EL as all that much better. Calling a function with parameters is complex and requires all sorts of fancy stuff that is not obvious (like TLD files) and go in places unrelated to the Java code of your beans and the JSP pages of your front end.
Sure, its great to not get null pointer exceptions, but how does a front end developer learn what variables are available in $sessionScope or other magic places? What is there depends on the internals of the beans, not the public API of the beans that are visible just from looking at the Javadocs.
I'm trying to be modern, but I don't get it. The tutorials show a half page of stuff, not how to do real applications. Anything more, and you are pointed to the Sun JSR documents, which are opaque.
Why is this better? And how do I learn to love it?
Most of what I have to say on the matter is captured in this article.
And I'm a lot better at technical explanations that motivation, but I'll address a few points...
Pat Farrell wrote:While scriptlettes may be a bit ugly, I'm not seeing EL as all that much better.
My reaction is 180. On top of the already crowded array of syntaxes in a page: HTML, JavaScript, CSS, and JSP actions, eliminating free form Java makes page so much easier to read and maintain.
A major benefit to me is that the JSTL and EL are limited. Generally, if you're finding something hard to do without having to resort to scriptlets, it's a red flag that it's something that should't be done in a view and should have been handled before even getting to the page.
Calling a function with parameters is complex and requires all sorts of fancy stuff that is not obvious (like TLD files)
I don't see TLD file as anything exotic. It's one of the first things I set up when creating a new app.
and go in places unrelated to the Java code of your beans and the JSP pages of your front end.
WEB-INF is hardly what I'd call "unrelated". It's the heart of the web app.
but how does a front end developer learn what variables are available in $sessionScope or other magic places?
That's immaterial and a situation exists whether you're using scriptlets or JSTL/EL. Unless of course you're arguing against Model 2 and arguing in favor of Model 1. That's a different matter entirely.
The tutorials show a half page of stuff, not how to do real applications. Anything more, and you are pointed to the Sun JSR documents, which are opaque.
No argument. The state of online and other docs are pitiful.
And how do I learn to love it?
I fell in love the very first time I saw it. So I'm not sure if I'm qualified to try and convince you...
Bear Bibeault wrote:I don't see TLD file as anything exotic. It's one of te first things I set up when creating a new app.
Well, to start with, I have no idea how to make a TLD that does anything.
I can't get code to call a trivial function with a parameter. I just don't get it.
One of the things that I hate about how Java and webapps have evolved is that doing anything takes a half dozen inter related files.
To do anything in EL that is not trivial, I have to write the Bean and the JSP and now the TLD and while I grok the Bean and JSP, I have no clue what a TLD is, or how to make one.
Of course EL is not everything, We need JSTL and perhaps standard & custom actions to fulfill our requirements. It's EL that provides standard way of accessing scoped variables etc... (appart from EL functions which can have some functionality inside). As Bear suggested making EL & JSTL limited is that making page authors work pretty easy and also JSP's main purpose more clearer (that it is for the view).
I know this is a very old thread, but I wanted to know if Pat learned to love EL, as I am in the same position as he was then
I pass a bean back from my servlet and it seems to me that
is much neater than anything EL offered.
Love? nope. Perhaps we are at friends with benefits stage.
I use it all the time, no scriptlets for me. But a number of things are very klunky. The lack of a proper if/then/else structure drives me nuts on nearly every page.
Pat Farrell wrote:well, <chose> has the function, but every other language has if/then/else
and I see zero justification for making EL special.
Not necessarily a justification, but XSLT uses <choose> as well. I suspect it's a consequence of having a language that can exist in XML format: if/then/else just doesn't work.
I've seen a few frameworks that try to use if-then-else in tags, and the result is pretty much the same as choose-when-otherwise, just with different tag names. It comes down to the differences between declarative and procedural markup I imagine.
And this isn't an EL issue at all, but a JSTL issue, so using it to say that the EL is badly designed based upon if-then-else structuring isn't accurate. Your beef appears to be with the JSTL.
I agree that it is just syntactic sugar, but when you have a distinction without difference, it raises the question: why?
EL and JSTL may technically be distinct, but they are effectively the same to me. And yes, I don't like them. Personal opinion, YMMV
I am ready for Java2 or some other language that starts from the ground up to deliver a clean, consistant compiler to run on the JVM. As I've written many times in this forum, I think Java has been hacked too many times, and pulled in too many directions. Its lost its charm and consistency.
Another thing I'd like to add is it seems like JSTL/EL are purposely designed so that things that you shouldn't be doing in the view are hard to do in JSTL/EL. For example, Pat mentioned earlier about the difficulty in calling a function using EL. Well, you shouldn't be calling functions in your view layer anyways. The View layer shouldn't change the state of the system, it should only render/display the current state
Jayesh A Lalwani wrote:Pat mentioned earlier about the difficulty in calling a function using EL. Well, you shouldn't be calling functions in your view layer anyways. The View layer shouldn't change the state of the system, it should only render/display the current state
Huh? You have two separate concepts conflated.
Functions don't have to change state. How about a function to convert data to JSON? Or perform a fancy Date range calculation?
Jayesh A Lalwani wrote:Pat mentioned earlier about the difficulty in calling a function using EL. Well, you shouldn't be calling functions in your view layer anyways. The View layer shouldn't change the state of the system, it should only render/display the current state
Huh? You have two separate concepts conflated.
Functions don't have to change state. How about a function to convert data to JSON? Or perform a fancy Date range calculation?
If your functions aren't changing state then why aren't they just getter methods? Functions don't have to change state, but by convention, any function that is just returning state is implemented as a getter method, and it is assumed that any function that is not a getter method might change state.
Of course, you can always implement a getter method without following the convention ,and then complain that it's difficult to call your getter from EL. It's hard for me to see how this is a problem with EL though.
Conversion to JSON shouldn't be done by the data bean/controller anyways. It is the job of the view to render JSON, not the bean or the controller. Besides why would you render JSON in JSP when there are so many other utilites available that can render beans into JSON
OK, I didn't think I was going crazy. Even though I can't find it in the Spec, I just downloaded Tomcat 7 (which supports JSP 2.2) and gave it a try. And calling a bean's general method as follows seems to work just fine.
Bear Bibeault wrote:OK, I didn't think I was going crazy. Even though I can't find it in the Spec, I just downloaded Tomcat 7 (which supports JSP 2.2) and gave it a try. And calling a bean's general method as follows seems to work just fine.
so you can get exactly the same functionality you could with a scriptlet, it looks almost identical, but you need an extra configuration file (the TLD)?
You're mixing things up. To define EL functions, you need a TLD entry. This has been true since JSP 2.0 and is a good thing. It defines high-level functions that can be used throughout the web app in a consistent manner.
What we're talking about here is a new capability with JSP 2.2 that allows calls to bean methods that accept parameters. No TLD entry necessary -- the method is inferred in the same way that properties are currently inferred.
Bear Bibeault wrote:...What we're talking about here is a new capability with JSP 2.2 that allows calls to bean methods that accept parameters. No TLD entry necessary -- the method is inferred in the same way that properties are currently inferred.
Looks cool. That'd eliminate EL functions altogether? Or is it only for instance methods?