tags:

views:

30

answers:

2

I'm trying to write a custom tab with attributes, but I can not get the tag handler class to read the attribute values. Using an <%= %> , I can get objValue to work. But objValue2 does not get evaluated when I use ${}.

jsp:

<% CommitmentItem ci = (CommitmentItem) request.getAttribute("commitmentItem"); %>
<myTag:calPOP objValue="<%= ci.getSource() %>" objValue2="${commitmentItem.source}" > </myTag:calPOP>

Tag Handler:

<getters & setters here>

public int doStartTag() throws JspException {
 pc.setAttribute("objValue2", objValue);
 System.out.println("Object Value = " + objValue );
 System.out.println("Object2 Value = " + objValue2 );

Console output:

Object Value = Contract W23AG-23
Object2 Value = ${commitmentItem.source}
A: 

Did you enable your web.xml for JSP 2.0 and expression language? If your web.xml is using an older DTD, the server will disable expression language so expressions such as ${foo} will not be expanded.

Try updating the web.xml namespace to enable JSP 2.0

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
     version="2.4">

 <!-- etc -->

</web-app>
locka
thanks. But unfortunately we are using jsp 1.2 and I have no control over the IT deptment upgrading to jsp 2.0 :( I use jstl so how come the c:out tag and its value attribute can evaluare ${foo}??
jeff
You don't necessarily have to upgrade anything. If your application server supports JSP 2.0 you just change your web.xml and redeploy. Obviously there may be reasons this is not possible (e.g. this is one jsp amongst dozens) but JSP 1.2 doesn't support EL except in standard JSTL libs. If you have your own tags, perhaps you can tap into that.
locka
there is no deploying, no web.xml file. I can drop jsp and class files into certain folders. Our application server has been half-assed backwards for years and I find myself spending weeks writing hacks to acheive a standard practice because IT at our company is not willing to upgrade our server. Thanks
jeff
A: 

If you are writing in JSP1.2, then EL expressions are not interpreted directly by the container. The JSTL tags themselves handle them. You might try the solution documented here Basically it involves using the ExpressionUtil.evalNotNull method (part of JSTL library)

Another thing that might work, but will potentially break other things:

<%@ page isELIgnored="false" %>

If it is the case of having a version of Tomcat that understands EL but is disabled via the web.xml settings, this will switch EL evaluation on for this page only. Of course any EL expressions in JSTL tags would subsequently throw exceptions as the JSTL1.0 tags don't accept runtime expressions.

evnafets
the coderanch solution works however I ran into another hurdle with using this approach for what I was ultimately trying to acheive, which is documented here <a href="http://stackoverflow.com/questions/3551973/dynamically-build-html-input-textbox-similar-to-struts-and-jakarata-tag-lib">here</a>
jeff