I have a JSP page that contains a scriplet where I instantiate an object. I would like to pass that object to the JSP tag without using any cache.
For example I would like to accomplish this:
<%@ taglib prefix="wf" uri="JspCustomTag" %>
<%
Object myObject = new Object();
%>
<wf:my-tag obj=myObject />
I'm trying to avoid directly interacting with any of the caches (page, session, servletcontext), I would rather have my tag handle that.
Its not encouraged to use Scriptlets in JSP page. It kills the purpose of a template language.
Use expression language:
The original syntax was to reuse '<%= %>'
So
See this part of the Sun Tag Library Tutorial for an example
A slightly different question that I looked for here: "How do you pass an object to a tag file?"
Answer: Use the "type" attribute of the attribute directive:
The type defaults to java.lang.String, so without it you'll get an error if you try to access object fields saying that it can't find the field from type String.
You can use "<%= %>" to get the object value directly in your tag :
and to get the value of any variable within that object you can get that using "obj.parameter" like:
For me expression language works only if I make that variable accessible, by putting it for example in page context.
Otherwise tas receives null.
And
<wf:my-tag obj="<%= myObject %>" />
works with no additional effort. Also <%=%> gives jsp compile-time type validation, while El is validated only in runtime.