This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Custom tag library 101 question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Custom tag library 101 question" Watch "Custom tag library 101 question" New topic
Author

Custom tag library 101 question

Karl Krasnowsky
Ranch Hand

Joined: Jan 16, 2009
Posts: 97
So I'm trying to map my java library model to something that can be used in a jsp taglib.

Core questions are...

the concept of "return"ing values from my tag handler to the jsp client is a bit unclear.

for example, let's say I have a class named MyItem
MyItem has two string value properties... 'key' and 'label' and there are corresponding getters and setters for these.
I also have an identifier that, well, identifies the MyItem...

so in Java code I can simply do this:


// and now



So I want to do something similar in my tag library...

is it possible to use java objects in this case in a similar fashion?



to do the above, would I have to specify the MyItem class in the TLD for the tag element such as:




Like that?


also, I'd like to next return a collection of MyItem objects to the jsp, so,
I have a MyItems class that serves a list of MyItem objects that also is instantiated using an id...


so, now ?




In the above, is there a TLD syntax that gives me the ability to declare that the mytags:myitems tag provides a Collection of MyItem objects so they can be iterated over as my pseudo code is representing?




[SCJP 6]
[SCBCD in process]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60761
    
  65

I'm not sure why custom tags come into the picture. Seems to me that you can do everything you need to do with <c:set> and friends.

You just need to learn the <c:set> syntax for setting bean properties. Hint: it's in the Spec.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Karl Krasnowsky
Ranch Hand

Joined: Jan 16, 2009
Posts: 97
Bear Bibeault wrote:I'm not sure why custom tags come into the picture. Seems to me that you can do everything you need to do with <c:set> and friends.

You just need to learn the <c:set> syntax for setting bean properties. Hint: it's in the Spec.


Hmmm, interesting. So it's very likely the jsp can simply use my library directly with no TLD descriptor...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60761
    
  65

No, I said I'm not sure you need to create any tags at all.

P.S. You're doing a lot of data machinations in the JSP; that's usually a red flag to step back and decide if what you are doing is something that would have been better handled in the page's controller.
Karl Krasnowsky
Ranch Hand

Joined: Jan 16, 2009
Posts: 97
Bear Bibeault wrote:No, I said I'm not sure you need to create any tags at all.

P.S. You're doing a lot of data machinations in the JSP; that's usually a red flag to step back and decide if what you are doing is something that would have been better handled in the page's controller.


Yep, understood. But you gave me another angle to consider that may be possible.

thanks.
Karl Krasnowsky
Ranch Hand

Joined: Jan 16, 2009
Posts: 97
Bear Bibeault wrote:No, I said I'm not sure you need to create any tags at all.

P.S. You're doing a lot of data machinations in the JSP; that's usually a red flag to step back and decide if what you are doing is something that would have been better handled in the page's controller.


Another thing... it wasn't my decision to go down this road to cover this requirement, it was mandated by the project's lead architect.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60761
    
  65

An architect is specifying code down to this level?
Karl Krasnowsky
Ranch Hand

Joined: Jan 16, 2009
Posts: 97
Bear Bibeault wrote:An architect is specifying code down to this level?

Well, he's specified the transport mechanism. This was before I got involved. I'm simply the transport implementer.
I too have reservations about the decision made to use tags for this, but here I am.

To be fair, I believe he felt that this was no more then an extension of the fmt tag service since it is a string localization exercise. However in this case it involves modeling the strings in an object hierarchy rather then simple string accessing.

I believe I have a few ideas on how to do this now and should be, in the very least, an interesting learning experience.
 
 
subject: Custom tag library 101 question
 
Similar Threads
Custom tag parameter
display a arraylist value in JSP using JSTL
c:set, problem with tlds.
help with custom tags
EL + Custom Tag troubles