• Post Reply Bookmark Topic Watch Topic
  • New Topic

Philosophical question on beans and el

 
Jacob Fenwick
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What advantage does using beans, el and tags give you over using scriptlets and expressions? Is this strictly a readability advantage or is there some other great feature I've yet to unlock?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While it does help to keep the readability quotient high as opposed to having many different types of notation in one JSP, I find that there is a more profound and subtle effect, which one comes to appreciate greatly the more one gets used to not using scriptlets in a JSP.

And that is that scriptless JSP pages guide page authors into keeping inappropriate processing off of the JSP, and forces one to think in terms of a strong separation between the controller and view layers.

The separation between the model and the presentation layer is easy to achieve if one has a mind to focus upon it. But the view/controller layer has always gotten relatively shorter shrift.

A good controller to view separation results in better-structured apps that are far easier to work with, be it creating, extending or maintaining.

I've been using JSP 2.0 and scriptless JSP pages for some time now, and it still amazes me how much easier dealing with the scriptless JSPs are when I have to go back for maintainence or extensions.

Philosophically, you can envision that scriptless JSPs are easier to work with, but the proof is in the pudding and once you experience the "clean" versions of JSPs, there's no going back.
 
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:

And that is that scriptless JSP pages guide page authors into keeping inappropriate processing off of the JSP, and forces one to think in terms of a strong separation between the controller and view layers.

With JSTL:SQL being the one glaring exception.
A pox on that one!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:

With JSTL:SQL being the one glaring exception.
A pox on that one!


Yes, with apologies Cecil B Demille's Ten Commandments: "Let the name of JSTL SQL be stricken from every record, every specification, every book. Let the name JSTL SQL be unheard and unspoken throughout the land."
 
Jacob Fenwick
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
While it does help to keep the readability quotient high as opposed to having many different types of notation in one JSP, I find that there is a more profound and subtle effect, which one comes to appreciate greatly the more one gets used to not using scriptlets in a JSP.

And that is that scriptless JSP pages guide page authors into keeping inappropriate processing off of the JSP, and forces one to think in terms of a strong separation between the controller and view layers.

The separation between the model and the presentation layer is easy to achieve if one has a mind to focus upon it. But the view/controller layer has always gotten relatively shorter shrift.

A good controller to view separation results in better-structured apps that are far easier to work with, be it creating, extending or maintaining.

I've been using JSP 2.0 and scriptless JSP pages for some time now, and it still amazes me how much easier dealing with the scriptless JSPs are when I have to go back for maintainence or extensions.

Philosophically, you can envision that scriptless JSPs are easier to work with, but the proof is in the pudding and once you experience the "clean" versions of JSPs, there's no going back.


Saying that you'll know it's better once you've changed to this methodology isn't a very convincing argument. It seems to be the argument I've seen most books and sites use as well.

One of my problems is that many of the people I work with use data driven architecture. Rather than using something like struts or jsf to generate all the html and javascript, they ususally use straight java, either inside scriplets or stored inside classes that are called through scriplets. All the branching of what html is generated is based on metadata stored in a configuration file.

By just changing some flags in an xml file, many views will change. For instance, many of the views are typical CRUD visualizations of a sql database. The metadata describes the tables that the CRUD visualize. A field in one of these tables could be defined to be shown as a pulldown. But if I wanted the field to be a regular textbox, I could just change the flag in the metadata, and many views would change. This makes separating out the view and the controller more difficult as a lot of the view code is generated at the time the controller figures out what it should look like.

This seems to be similar to tags, but when I say we should go to tags people argue that there's no measurable benefit in taglibs.
I'm in the process of looking for a way that el, beans and tags might make a process like this easier, but I'm having a hard time convincing people of this.

Most of the developers don't see a problem with mixing in all these scriptlets that generate tons of dynamic code, but I think the current system is somewhat unmaintainble. However, I'm not all for switching to more static jsps because then you'll have hundreds of individual views that all have to be maintained separately, and you lose a lot of the flexibility provided by configuration files. Hopefully I'll find the happy medium.
[ August 18, 2006: Message edited by: Jacob Fenwick ]
 
Jacob Fenwick
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Meh, I just discovered http://www.javaranch.com/journal/200603/Journal200603.jsp#a5
That helps a little in giving me an overview of the different "Models". I guess I'm making the transition from Model 0 to Model 1 right now.

However, it still doesn't give a very good explanation about my more specific questions about view generation. The Model 2 idea seems to focus on building lots of little jsps where the view for each is fairly specific.
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
philosophically, JSPs are (or should be) only about displaying data, not manipulating or even generating it.
Scriptlets defy that purpose.
 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am in practice a desciple of Bear's. Hehehe. Anyway, I'd like to site m experience as an example:

I work alone... Yes... Alone... I work as a lone Java, PHP, or whatever you could call me in a small freaking company which I'm about to leave in a couple of days(or weeks). Making a scriptless JSP not only helps you create highly maintainable code, it also saves you from a lot of headache like for example... You need to change the layout of your app, which happens to me most of the time... And yes, it makes good separation of your view/controller. It gives you good discipline because it forces you to do just that(separate view from controller), and thus also improves your thinking because you get to think of a more elegant way of solving yout problem. I too came from a previous company where they used 100% scriptlets in their JSP. Thus, I gave it the term JSASP and JSPHP because they code as if they're using those other technologies...

Without JSTL and EL, wouldn't have lasted even a month...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!