• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP EL ? How common is it ?  RSS feed

 
Sirisha Reddy
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
just wondering how common is it to use JSP EXPRESSION LANGUAGE (EL) in real world programming??

Thanks,
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I only write scriptless JSP pages exclusively containing template text, JSP standard tags, my own custom tags, JSTL tags and EL expressions. No Java, no Java scriplets, no Java scriptlet expressions. And my life is full of sunshine, flittering butterflies and singing birds.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
been on the LSD again Bear?

But Bear is right. Scriptless JSP are upon us. While not everyone by far has seen the light and there's still a lot of old work around that's never been updated we're getting there slowly.
 
Robert Hayes
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I chose JSP + JSTL/EL for my current project and couldn't be happier. It is VERY powerful in what it can do with a small amount of code. A case in point would be pulling data out of collections. It's extremely easy to iterate over collections of java-bean type model objects for displaying tables of data: with NO casting. Here's an example:

An ErrorDetails class is a java bean that contains, among other things, an error description. A centre (branch) can generate several of these ErrorDetails in a day. And there are several centres. So I have a collection of centre objects and a collection of ErrorDetails arrays. To display all errors for all centres, I simply pass the two collections to the JSP and use JSTL/EL like this:



The JSTL SQL tags are nice for prototyping web-pages, but I don't use them for production apps obviously.

As for how many people use it -- I don't know. But if you get a chance you should try it. Any time now I see Java code in JSPs, I go "eeewwww!"
[ March 25, 2005: Message edited by: Robert Hayes ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
been on the LSD again Bear?


Don't need it. I'm quite weird enough on just caffeine!


Any time now I see Java code in JSPs, I go "eeewwww!"


I know. It just seems so, dirty.


Some have pointed out that scriptless pages are "flawed" because you can't do everything with them. But to me, that's the point. By limiting your pages to what is possible with JSTL, EL, and the standard and custom tags, you are essentially forcing yourself to design good controller->view interfaces.

If you can't do something on a page using these mechanisms, it's a red flag that you are probably doing something that you shouldn't be.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I went through a great amount of work to eliminate scriptlets before EL and JSTL were out so my current project has been scriptless for years. it uses <jsp:getProperty and custom tags for everything.

I'm actually looking forward to a new project where I can use EL.

For me, the only thing uglier than scriptlets in JSP pages is a mixture of different approaches to getting rid of them. Or even worse, scriptlets AND other approaches.

JSP is on the fast track to becoming a "write-only" language.
[ March 26, 2005: Message edited by: Ben Souther ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP is on the fast track to becoming a "write-only" language.


I thought perl has that distinction!

Seriously, I strongly disagree. I find that since scriptless pages use no jarring Java scriptlet notation, that the pages become much much more readable and clear when only markup/EL is used.

Picking good names for scoped variables, and appropriate structures for page-bound data, make EL expressions intuitive and obvious.

I've converted all my client sites over to scriptless pages, and when they need updating or enhancing, the pages are a joy to work on.
[ March 25, 2005: Message edited by: Bear Bibeault ]
 
Robert Hayes
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear,

Since you seem to have many client sites, I have a question for you: in the past 2-3 years have you ever heard of a project design that completely throws out the view layer altogether?

There is a consultant down the hall from me that convinced the management that the web-pages for his project were "too dynamic" to use JSP. And therefore he's doing everything from servlets (ie: out.println("<b>Oh my god!</b>")

When I asked him if he knew about JSTL/EL he said "No". And I left it at that (I'm a consultant on another project -- not his).

(ps: I don't mean to hijack a thread; so I can send you an email if it's more appropriate)
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, never.

convinced the management that the web-pages for his project were "too dynamic" to use JSP.


Translation: "I don't know JSP very well."

And therefore he's doing everything from servlets


And what a horrible nightmare to extend and maintain it will be.

As much as I dislike sticking Java into JSPs, it really makes my skin crawl to see HTML built up in Java code.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:


I thought perl has that distinction!

Seriously, I strongly disagree. I find that since scriptless pages use no jarring Java scriptlet notation, that the pages become much much more readable and clear when only markup/EL is used.

Picking good names for scoped variables, and appropriate structures for page-bound data, make EL expressions intuitive and obvious.

I've converted all my client sites over to scriptless pages, and when they need updating or enhancing, the pages are a joy to work on.

[ March 25, 2005: Message edited by: Bear Bibeault ]


I don't think we're disagreeing. Scriptless pages are far superior what we had before and.. Perl, certainly, holds the title for write only languages, at the moment.

In the right hands, JSTL and EL are tools that make for some of the most readable web code imaginable. I've yet to see a web platform that provides for better separation of form and function than JSP/Servlets, especially now that we have JSTL and EL.

The problem is, that in the wrong hands, they are just "another" syntax that can be mixed freely with all the existing ones. I've seen very clean Struts apps get thoroughly corrupted and bastardized by people who don't know the value of MVC. It starts out as "just this one scriptlet" to fix a really hot bug or, worse, a hotshot consultant who wants to show how quickly he can solve a problem will come along and put a hack right in the view tier. The pointy haired boss walks away wondering why the original authors took so long to accomplish the same thing.
Once you cross that threshold the mess spreads like a cancer.

In this forum alone, I've seen plenty of examples where people mix scriplets, jsp:Xxx, JSTL, and EL all in the same posted code.

With all the available options, the key will be to pick one and stick with it, religiously, no matter what. I'd love to start using JSTL and EL in my current project but I won't.... not unless I can replace the current framework, entirely.

Scriptlets and HTML are nowhere near as bad as an indecisive mixture of 3 or four different approaches within the same project.
[ March 25, 2005: Message edited by: Ben Souther ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Robert Hayes:
... the web-pages for his project were "too dynamic"


So he's advocating a LESS flexible approach?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is, that in the wrong hands, they are just "another" syntax that can be mixed freely with all the existing ones...


Ah, yes. Agreed. If I were more musically inclined, I could write a very sad country/western song regarding some of the really bad JSPs I've seen!

And a sadder one about "hot-shot consultants"!

bad as an indecisive mixture of 3 or four different approaches within the same project.


Amen, brother!

P.S. 6kth post!
[ March 25, 2005: Message edited by: Bear Bibeault ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. 6kth post!

Gotcha covered.

The gun was already loaded when you walked into the room (saloon).
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that why I've felt like I'm being watched?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HEHE, watching too much Deadwood.
Back to topic.

What would be a real saving grace would be a context wide -scriptless directive that work like ASP's "Option Explicit" or Perl's "strict" directives do with undeclared variables, amd would cause a Jasper (or whatever JSP compiler) to blow up when wayward developers try to cross the line on anotherwise clean project by adding scriptlet tags.
[ March 25, 2005: Message edited by: Ben Souther ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP 2.0 has just such a mechanism to disallow scripting on all, or individual pages. I don't remember the details as I've never used it (I don't need Jasper enforcing no scriptlets for me). But I can see where it'd be nice to use in a multi-author shop where not everyone may have discipline.
 
Robert Hayes
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
No, never.



And what a horrible nightmare to extend and maintain it will be.

As much as I dislike sticking Java into JSPs, it really makes my skin crawl to see HTML built up in Java code.


Apparently the web app is very user role-based which affects the view. For example, one page may need to be displayed 20 different ways depending on the security role the user falls into. For him that equates to 20 different models basically (although he's not using MVC).
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
JSP 2.0 has just such a mechanism to disallow scripting on all, or individual pages. I don't remember the details as I've never used it (I don't need Jasper enforcing no scriptlets for me). But I can see where it'd be nice to use in a multi-author shop where not everyone may have discipline.


You should be able to disable/enable scriptlets using something like:



You can even go so far as to define scripting to be enabled/disabled for certain pages and not for others since they use the url-pattern element. The same thing can be done for EL.



Perty nifty.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
, one page may need to be displayed 20 different ways depending on the security role the user falls into.


I have just such a web app too. I'm not sure where he thinks that conditionlizing the build up of HTML in Java code is any more effective than doing the same within a JSP, preferably using JSTL if tags.
[ March 26, 2005: Message edited by: Bear Bibeault ]
 
Andles Jurgen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heres my take on all this:

First up, lots of JSTL in a jsp does ont constitue a scriptless page. Its just scripting with a different syntax, a syntax that is not java and requires one more thing for a java developer to learn.

There's no point getting all negative on scripting and then dumping a whole buch of JSTL in the page, its just as bad, if not worse. JSTL only makes sense if the person doing it is a page author or designer that does not know java, or if the person doing is expecting the page to in the future be edited by such a person. Even then I think its a hassle fo rthat page author as it it makes the code seem more HTML'ish and creates a lesser distinction between what is obviusly logic and what is obviuosly mark-up. Any benefit of JSTL here is minimal uless the page author is working closely with the page author and the page author unserstand the ramifications of editing the JSTL.


JSTL has a place I guess, but I personally do not like it at all. My pages have minimal scriping in them anyway, and the few sriptlets I had in a page allowed me all the control I needed in a language I was comfortable with. Now I feel guilty if I add some java to my java based web pages - stupid.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First up, lots of JSTL in a jsp does ont constitue a scriptless page. Its just scripting with a different syntax


Agreed, 100%, model 1 programming, in any syntax is still model 1 and it's ugly.

But

That isn't the point of JSTL and EL. They're designed to work in an MVC environment. Unfortunately, a lot of people are missing the point, resulting in a lot of unreadable JSP (and thus, my comment about it being on the fast track to becoming a write-only language).

MVC is designed to (among other things) take the data access, business logic, OOP, and program flow out of the view tier. Unfortunately, the designers of the view tier still need to do some minor programming for things like accessing properties from beans, looping through lists, etc, etc....

For these tasks we were initially given the jsp:useBean, jspSetProperty, and jsp:getProperty tags. These, along with the ability to write custom tags, are enough to completely eliminate the need for Java scriptlets in the view tier. I can say this with all confidence because the project I work on all day has no scriptlets whatsoever. It also has no EL or JSTL (but only because these were just coming out when I started it.)
There is a huge benefit to this. We sell this app to customer's who want to customize the look and feel so that it matches their own sites. We can safely advertise that our clients don't need any Java training to do this. Any competent web designer should be able to sit down with our pages and understand what's going on within a day. Our own web designer has no experience with Java and does just fine.


Now, here are, some of the problems that the real world has thrust upon us. There are certain things that all web apps will need to be able to do, like loop through a list to print the results. Because of this, all companies who want to get programming logic out of their view tier have been forced to implement the same set of custom tags. JSTL is the perfect solution to this. By having a standard tag library that we can eliminate tons of duplication.

The next problem is that Java developers don't want to stop the world every time the design department needs a new feature in the view tier.
Likewise, designers don't want to wait a week for a new custom tag to be written for something as simple as an alternating graybar table (My framework actually has a clean solution to the graybar table but that's beside the point ). The result of this problem usually ends up being a "Just this one time, until we can get the tag made" scriptlet.

You've now got a situation where non-Java developers are working directly with Java. If you haven't had the joy of presiding over this situation, think about explaining:
  • The difference between '==' and '.equals' when comparing strings.
  • Why '+=' is less efficient than using a StringBuffer for String concatenation.
  • How accidentally leaving out a curly brace can lead to a "try without catch" error message.
  • The whole threading and "why you can't use that instance variable in your JSP" conversation.

  • And, once you let the scriplet camel get it's nose under the tent....

    Clearly, the best solution to this is a very simple, watered down, expression language that page designers can use for programming issues that affect only the view.


    My pages have minimal scriping in them anyway, and the few sriptlets I had in a page allowed me all the control I needed in a language I was comfortable with.

    I agree that Java programmers like to work in Java but for large, multi-developer environments it has to be expected that non-Java developers will have their hands in the soup and anything that keeps their hands off of actual Java code, is a blessing in this situation.

    ===============================================

    The nasty side effect of this 'evolutionary' process is that we now have close to a half a dozen ways to express the same thing from within a JSP.

    One of the great strengths of Perl was that people from all different backgrounds could walk right in and start writing it. You could use awk, sed, and the syntax from almost any popular Unix scripting language imaginable to build your Perl scripts. The problem with this is that two different Perl developers could sit down and write the same thing, switch scripts, and not be able to read any of what the other developer wrote. This is where we got the phrase "Write-Only Language".

    To a developer who has only ever used scriptlets, a page written with JSTL and EL is going to look very foreign. Likewise, a page full of scriptlets is going to be very tough for someone raised in a JSTL/EL environment. The biggest nightmare will occur when multiple developers write to the same JSP with whatever syntax they are most comfortable using. I can tell, without any doubt, this will happen and it's going to be a big problem for JSP. One of the most common arguments I hear for PHP over JSP is that it's much simpler (as if we couldn't sit down and write model 1 pages in JSP that look exactly like their ugly PHP pages). The same pointy haired boss who helped bring this situation about, by applauding the developer who dumped scriptlets in an all MVC app to quickly fix a problem, will start considering PHP or CF or .NET simply because this can't happen in a language with far fewer options. Sadly, he'll have a point, because, a page full of scriptlets (or even a pure model1 app) is still better than in indecisive mixture of 3 or 4 different architectures/syntaxes.

    The attributes pointed out by Gregg will help in this respect.
    I plan on implementing them as soon as I get back to the office.
    [ March 27, 2005: Message edited by: Ben Souther ]
     
    Jeroen Wenting
    Ranch Hand
    Posts: 5093
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Bear Bibeault:
    No, never.



    And what a horrible nightmare to extend and maintain it will be.

    As much as I dislike sticking Java into JSPs, it really makes my skin crawl to see HTML built up in Java code.


    There are of course options and that's to use templatised HTML or XML/XSLT.
    I've done both in the past and they can provide alternatives to JSP/JSTL.

    Whether they're cleaner alternatives is open for discussion (though I do like the idea of having XSLT and XML instead of JSPs, makes providing for multiple platforms quite simple (just swap in a different XSL file)).
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!