jsptagsjsp-tags

Why Can't JSP 2.0 Tag Files Have Body-Content of "JSP"?


The "new" JSP 2.0 tag file tags are incredibly useful, and for most cases (at least that I've seen) they provide a far more readable format than a Java class. However, while tag files can do almost everything a Java class tag can do, there is one giant thing they can't do: have "scripting" body content (ie. "<%" stuff between the start and end tags).

So, my question is multi-part:

  1. Does anyone know why (from a design standpoint) this is? Is it inherently impossible for tag files to have such content due to the way they are implemented or something?
  2. Does anyone know if there are any future plans to allow for body-content="JSP" in tag files (in a future version of the JSP standard maybe)?
  3. Does anyone know of any way to "hack" tag files to allow them to have scripting content (like by having a body-content of scriptless, and then processing the contents somehow)?

Basically my dream is to someday write tag files which don't result in exceptions if someone puts a

<%= myVar %>

inside, and I'm just trying to determine whether that dream is hopeless or not.


Solution

  • The JSP tags were designed this way so that there will be a complete separation of concerns between the presentation layer and the code behind. JSP pages are supposed to be edited by designers and therefore using Java code isn't appropriate.

    I suppose that you need to adapt your coding habits in this philosophy. You can move all your Java code to your beans. Do whatever is required there and then pass the appropriate bean to the JSP page. Exception handling should also go there. If this isn't enough, you can always create your own tags to use.