This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it easy to create custom tags in JSP/JSTL

 
Kenneth Gustafsson
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm in the beginning of a project, no code has yet to be written. I want to reuse as much code as possible so I thought I'd write custom components which I then just use.

The components I'm thinking about are for various things. It could be a component which shows a static message if the user hasn't got JavaScript enabled, and a dynamically updated one if it's available. Other components could help with easy form creation and validation. Yet other components could handle nice tabular lists which you're able to update and re-sort using JavaScript.

Is it easy and flexible to do this using JSP or JSTL? And if it's easy and flexible using both ways, do you have any recommendation regarding if I should choose JSP or JSTL?

As a last note. I need to create custom components myself. :-) I can't imagine that all the custom things we'll use are available in any library. However I will use the help of jQuery to create the dynamic things.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not really a question of JSP or JSTL. Just about all JSP pages will use JSTL tags. But JSTL tags are standardized; they aren't related to whatever tags you develop.

Since you mention lists, you may want to check out the DisplayTag tag library on SourceForge. It handles list display, paging, data export etc. nicely.
 
Kenneth Gustafsson
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, thanks for informing me! I was more thinking about using only the XML structure or the normal JSP structure.

Still the issue is code reuse and I'm wondering how hard it is for me to write my own tags/components. It's great that there are third party libraries with lots of tags, but I want to create some of my own.

For example, if I want to create a special kind of input text field which has some validation information as well:

<myinputtextfield id="textfield" param="name" desc="Input name:" " longdesc="Write your first name followed by your last name" mustmatchpattern="([a-z]{2,10}+\s){2}" onvalidationfailure="You must input your first name followed by your last name"/>

It will output a text field together with some JavaScript for validation as well as visual bling-bling. I might base it on jQuery, echo or something else.

Would that be possible? Would it be easy?
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A decent tutorial on writing tags libraries is at http://www.orionserver.com/docs/tutorials/taglibs/index.html
 
Kenneth Gustafsson
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you! I'll be sure to read it. Just a quick question for you or someone else who is knowledgeable.

If there were lots custom ways needed to handle forms and other things and you wanted to reuse code to minimize bugs and development effort. Would you go for a JSP solution then, or would you use JSF, or maybe Wicket?
[ July 24, 2008: Message edited by: Kent Larsson ]
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a loaded question, and you'll get lots of different opinions. Personally, I'd use a framework for anything but the simplest forms. My favorite at the moment is Stripes. But the answer depends very much on whom you ask :-)
 
Kenneth Gustafsson
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for answering me even though it was a loaded question! :-) Personally I lean mostly towards Wicket.

On a general basis, and as a follow up question, why would you use a framework instead of a plain Servlet+JSP architecture for anything but the simplest applications?
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because a framework can do many things that otherwise one would have to code by hand: mapping of requests to server classes, binding of request parameters to Java objects, validation, form generation including repopulating of forms and display of error messages, ...

The reason I like Stripes in particular is that it keeps all the configuration in the Java class in the shape of annotations - no config files to maintain. It also emphasizes "convention over configuration", meaning that if HTML form fields and Java classes/methods/fields are named in certain standard ways, then one doesn't need to configure them at all - binding, mapping and validation are done automatically based on the names and IDs of things.
[ July 24, 2008: Message edited by: Ulf Dittmer ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic