Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15439
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15439
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because a bean isn't a user-interface component.
 
Kris Schneider
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, bean tags aren't UI components either.
 
Kris Schneider
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic