Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

Custom taglibs: do I need one class per tag?

Thread view: 
james - 07 Jun 2006 04:20 GMT
I've been crash-course learning java, jsp, servlets, struts, etc
(Coming over from php & asp, and I love it!).  I'm trying to figure out
proper style in the process.

I've been creating a custom taglib for my app to retrieve data so JSP
pages can render them.  Do I have to create a separate class for each
custom tag?  For servlets/struts, I can use a DispatchAction class to
feed multiple actions into the same class, using a parameter to tell
which method I want to invoke.  Is there anything similar with custom
tags?  I would like to have the following.

<myApp:getItems parameter="allItems"/>
<myApp:getItems parameter="oldItems"/>

And they would correspond to the following methods, respectively:

class GetItemsTag extends TagSupport {
 public void getAllItems() { ... }
 public void getOldItems() { ... }
}

I can do this with two separate tag classes, or by using a big "if (
parameter.equals(...) ) {" for each action, but this would seem to make
things just one bit simpler.  Is there any such shortcut?  Am I trying
to abuse the model / view paradigm?

Also, as far as I can see, in a typical struts app I have a couple of
possibilities for rendering pages:
1) I can goto page.jsp and use custom tags to grab all the data
necessary, then post any forms to an action...
2) or I can always go to page.do, have that action setup all the
necessary data in request vars, and then forward to the proper
rendering JSP page.

Are both of these styles acceptable?  Is either blatantly wrong, or
does it come down to preference and pros/cons of each style?  What are
your preferences?

Thanks for all feedback, I love java after dealing with ASP / PHP for
so long.
James
Venkatesh - 07 Jun 2006 14:05 GMT
As far as I know, doStartTag is the only method that is always called
for each tag.

The jsp tags framework doesn't provide implicit support for different
method invocations based on some attributes.

-Venkatesh

> I've been crash-course learning java, jsp, servlets, struts, etc
> (Coming over from php & asp, and I love it!).  I'm trying to figure out
[quoted text clipped - 37 lines]
> so long.
> James


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.