aspose file tools*
The moose likes JSP and the fly likes How to get to the custom tags on a page from a scriptlet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to get to the custom tags on a page from a scriptlet?" Watch "How to get to the custom tags on a page from a scriptlet?" New topic
Author

How to get to the custom tags on a page from a scriptlet?

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14342
    
  22

My colleague has an ASPX page that contains server controls (the equivalent of custom tags in a JSP page). In this page, he has a scriptlet (in C#) that looks up one of the server controls on the page by ID, and then calls a method on it. It looks like this:

So, converted to Java / JSP terminology: he has a scriptlet that looks up a custom tag on the page according to its Id attribute, and then calls a method on the tag handler object for that custom tag.

Is something like this possible when using JSPs?

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Ewwwwww.

But as far as I know, this isn't possible: the structure of ASP and JSP pages is different; ASP pages are more component-oriented. It'd probably be possible if you were using a component-based page/tag rendering system, but if it's action-based, probably not. The JSP is rendered into a servlet, which is just making function calls to the tag--you'd have to demangle the tag names/instances, and even then, I don't know if it'd work.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14342
    
  22

Thanks. Yes, this looked strange to me too, and you probably can't (easily) do the same kind of thing using JSPs. He'll have to find some other way to solve his problem.
Kris Schneider
Ranch Hand

Joined: Feb 14, 2001
Posts: 71
Maybe I'm missing something, but how is this much different than:



I guess the point is to think about using beans instead of tags/actions. Is there a reason for requiring a tag? Of course, servlets and filters are other options...
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Because a bean isn't a user-interface component.
Kris Schneider
Ranch Hand

Joined: Feb 14, 2001
Posts: 71
David Newton wrote:Because a bean isn't a user-interface component.


So, if I used the Struts bean tag instead then it would be a UI component?

Edit: Just goes to show how much that response made my eyes cross, because, you know, <jsp:useBean> really is a tag...
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

No, bean tags aren't UI components either.
Kris Schneider
Ranch Hand

Joined: Feb 14, 2001
Posts: 71
David Newton wrote:No, bean tags aren't UI components either.


Got it - this is a "know 'em when I see 'em kind of thing". So, do we know that <prefix:Query> is more like a bean tag or more like a UI component...however that's defined...
 
jQuery in Action, 2nd edition
 
subject: How to get to the custom tags on a page from a scriptlet?