aspose file tools*
The moose likes JSP and the fly likes custom tag not called at all Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "custom tag not called at all" Watch "custom tag not called at all" New topic
Author

custom tag not called at all

gigi sheh
Greenhorn

Joined: Oct 15, 2012
Posts: 10
Hello,

I am totally clueless and desperate at this moment. As someone usually working at the backend service, I am working on a project that uses a custom tag in a JSP file. Here is the tag descriptor



Here is the Tag handler


And here is the JSP fragment that uses the custom tag


Everything seems working fine except that the custom tag handler does not get called at call. I set breakpoint and it never stops there. The JSP page is displayed fine, only not showing the custom tag content :(
and there is no logged error/warning from the log. The tld is found fine. Can someone please give me some hint/helps on how to troubleshoot this? Like what classes called/validated the tag handler so I can logging those classes at DEBUG level to see what goes wrong. Any helps would be deeply appreciate it. It is so frustrating

Thanks a lot
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

Have you checked the HTML being sent to the browser to see what it contains? Is the tag still there, uninterpreted? (it shouldn't be)

Why are you extending classic Tag rather than modern SimpleTag?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 954
    
  13

The fact that you are using doStartTag() tells me that you are creating this based on the Classic Tag design. Why do you want to torture yourself like that? Implement it as a Simple Tag.


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
gigi sheh
Greenhorn

Joined: Oct 15, 2012
Posts: 10
Thank you for the replies. The tag is completely gone from the HTML. It is a legacy project that is assigned to me for a bug. Not sure why Tag interface is used rather than SimpleTag. I guess I can switch to SimpleTag. But what can I do in general to troubleshoot/debug such issues? I don't know what direction to look into. If I knew more about the internal mechanism of how custom tags are called/activated, then I could have set those classes at DEBUG logging level or set breakpoints within them
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 954
    
  13

So you are stuck with fixing legacy code. It happens. I would put a "System.out.println("running doStartTag()"); as the first line of your doStartTag() method. If that prints, then you know the method is getting called. Next, set a breakpoint there and single-step through it.
gigi sheh
Greenhorn

Joined: Oct 15, 2012
Posts: 10
I have set breakpt within doStartTag, it is not called at call
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

Try logging as suggested. I have found breakpoints in web apps to generally be unreliable. What IDE are you using?
gigi sheh
Greenhorn

Joined: Oct 15, 2012
Posts: 10
intellij. I will try logging too.
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 954
    
  13


This doesn't seem right. You shouldn't need to implement the Tag interface. Extend the TagSupport class instead.


This doesn't look right either. A classic tag inherits the pageContext member variable from the TagSupport class. I think you are missing this because of the interface implementation you had above. Extend TagSupport and change this line to
gigi sheh
Greenhorn

Joined: Oct 15, 2012
Posts: 10
still not working. The logging statement is not printed either



can someone please point me to the stack that invokes the custom tag so I can set some logging/debugging there? I feel I am fumbling in the dark
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

You're not going to be able to easily insert logging into the inner Tomcat code. Have you switched to using TagSupport as suggested?

(Still recommend porting to SimpleTag)
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 954
    
  13

Now you are trying to switch to a SimpleTag. Stick with the ClassicTag that you started out with. It should look like this:


Note that this file MUST be /WEB-INF/ or /WEB-INF/tags/ or a folder below that. Make sure your tld file is in /META-INF/TLDS. I suspect you have your tld in the same folder as your URI, namely here:

That won't work. Remember, that URI is not a location, it's just a unique identifier for namespacing purposes. It could just as easily be "123ABC" as long as it matches what's in the tld file.
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 954
    
  13

Lol. We're giving you some conflicting info here. While SimpleTag is a much superior method of doing this, I'm trying to get you working without a lot of refactoring. In the end, I agree with Bear, I would scrap the whole thing and rewrite as a SimpleTag but I got the impression that you are just trying to make a change to existing code so I'm not sure if you're ready for that yet.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

My recommendation is to always use URIs that follow the proper format that look like URLs. That way, no one is fooled into thinking it is a file path. (Of course, then some people think that they are URLs rather than URIs, so I guess you can't win.)
gigi sheh
Greenhorn

Joined: Oct 15, 2012
Posts: 10
we use JBoss 5.0.1. Not insert logging but I mean to set the logging level of the classes in the custom tag invoking stack at DEBUG so more information will be outputted
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 954
    
  13

Bear Bibeault wrote:My recommendation is to always use URIs that follow the proper format that look like URLs. That way, no one is fooled into thinking it is a file path. (Of course, then some people think that they are URLs rather than URIs, so I guess you can't win.)


That's always been an area of confusion. My point was that if he's put the tld file under WEB-INF the container won't find it. It has to be under META-INF. Tag files go under WEB-INF. More confusion. I suspect that's why the code isn't running; the container just can't find the files in the expected locations.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

Actually, the container will find tlds under WEB-INF in a web app. But only if the URI is proper and matching. If the tag library is jarred, that's when META-INF comes into play.
gigi sheh
Greenhorn

Joined: Oct 15, 2012
Posts: 10
the tld seems locatable fine. I have this line in the log

DEBUG [org.apache.catalina.startup.TldConfig] Scanning TLD at resource path '/WEB-INF/tlds/myTags.tld'
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 954
    
  13

Bear Bibeault wrote:Actually, the container will find tlds under WEB-INF in a web app. But only if the URI is proper and matching. If the tag library is jarred, that's when META-INF comes into play.

I told you I'm having trouble with that chapter<sigh>. You are absolutely correct.

I'm running out of ideas, so let's back up and start from square one. gigi, please post the latest version of your tag handler, the tld, and the jsp, and I'll create a project and try to duplicate the problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: custom tag not called at all