wood burning stoves*
The moose likes JSP and the fly likes jstl calling a method on a class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "jstl calling a method on a class" Watch "jstl calling a method on a class" New topic
Author

jstl calling a method on a class

Max Tomlinson
Ranch Hand

Joined: Jul 17, 2001
Posts: 365
Hi-

I'm new to jstl. We have a simple web app, MVC1 (no controller servlet) and I have a simple client class (foo) that wraps server calls.

So for example:

Collection c = foo.getSellerInfo(String1, String2, String3);
etc.

how do I turn this into jstl?

easy to do with a tag or a scriptlet --

do I use Usebean? Can I pass arguments with usebean?

many thanks
Max
[ January 13, 2005: Message edited by: Max Tomlinson ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60776
    
  65

The terms JSTL and 'call a method' are incompatible. The purpose of JSTL (and EL and other JSP 2.0 additions) are to try to steer people away from on-page scriptlets and processing.

In JSTL 1.1 there is a facility for generating function calls, but it's not general purpose and could not be used for the purpose you are asking (without hoops of fire).

The utility of the JSTL and EL is severly hampered in a Model 1 architecture such as you describe (no servlet controller to marshal scoped variables on behalf of the page).


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
I'm ever more thinking of joining the JCP and submitting a JSR to remove the scriptlet functionality from JSP completely.
What keeps me back so far is the bureaucracy of the JCP (I've better things to do with my time) and the fact that we've a mass of old style JSPs and controlling servlets at work that I don't fancy updating


42
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Max Tomlinson:
Can I pass arguments with usebean?


You can set and get string properties:


Like with JSTL, this is really designed for Model II, where you're doing all the heavy lifting in servlets and beans.

If you're going to do Model1 coding, let it look like model1 and don't bother with useBean or JSTL. Having one foot in each boat just adds unnecessary complexity.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Max Tomlinson
Ranch Hand

Joined: Jul 17, 2001
Posts: 365
Thanks for the replies-
looks like I can't do what I want with jstl then -
quite honestly I don't see the advantage to it unless one is using a strict mvc architecture...a page of jstl looks as messy as a sciptlet to me...better to use a custom tag
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60776
    
  65

quite honestly I don't see the advantage to it unless one is using a strict mvc architecture


I think it has value in any case, but the utility of the JSTL and EL is vastly greater for web apps that follow the preferred Model 2 architecture.

a page of jstl looks as messy as a sciptlet to me


You're either writing very messy JSTL or very neat scriplets. I find them worlds apart.

better to use a custom tag


They're by no means mutally exclusive. All of my pages are a combination of JSTL and my own custom tags. What you won't find on them are scriplets and scriplet expressions.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you're going to do branching, exception handling, validating, database handling (sql) etc.. in your JSPs... then JSTL, custom tags, EL, and the like are just more technologies to have to learn and keep up with. Just use scriptlets and work in one language -- Java.

The point of these technologies is to help extract the heavy lifting from the JSPs and move it into Servlets, Beans, and, plain old Java classes.

When these tools are used correctly, you end up with very clean JSPs that only contain markup and client side code (javascript). You never have to stop and ask: "Is this for-loop is serverside or client side?". When mis-used, you end up turning JSP into Perl -- one massive language with so many syntactic styles that no two developers can read each other's code.

There is still a place for Model1, IMHO. Prototypes, small - one developer apps, vaporware, etc can be thrown together very quickly this way. If the project is going to have multiple developers and/or web designers OR if it can possibly become a medium or large sized production app, then it makes sense to figure out how to use these tools to achive the kind of separation of concerns that allows a project to grow and be maintained without turning into spaghetti code.


PS: before anyone starts flaming... I mean no disrespect to Perl. I like it. It's funky, cool, and indespensible for unix administration. It just wasn't made for enterprise development efforts....
[ January 14, 2005: Message edited by: Ben Souther ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: jstl calling a method on a class
 
Similar Threads
print server time
JSTL create bean
HFS: ambiguity in coffee cram ?
Design Question JSTL or Scriptlet
Scope of jsp:useBean