Solved

JSP Custom Tag Attribute

Posted on 2004-03-31
11
1,660 Views
Last Modified: 2013-11-24
Hi,

I've written myself a custom tag for a JSP, but i'm having a little trouble passing it an attribute.

The tag is supposed to be passing a parameter from a form that was submitted from a previous page, so i'm using:

<tag:hashingTag valueToHash="${param.answer}" />

This is what i've been using for the standard tags to pass variables, but for my tag it just passes in the String "${param.answer}", rather than the value that variable is holding.

Is there some setting i'm supposed to set to tell the tag this is a variable, not a String?

Cheers.
0
Comment
Question by:playerone
  • 5
  • 4
  • 2
11 Comments
 
LVL 7

Expert Comment

by:searlas
ID: 10724415
See:
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPIntro7.html

Depending on your application server, you may need to specify (at the top of your page)
<%@ page isELIgnored="false" %>

Additionally, the attributes on your custom tags must be set up in the tld file as <rtexprvalue>true</rtexprvalue>
0
 
LVL 7

Expert Comment

by:searlas
ID: 10724430
Reading your post again, since you're successfully using "${...}" with the standard tags, then it would point to the problem being in your .tld file, and needing to declare <rtexprvalue>true</rtexprvalue> within the appropriate <attribute> elements.
0
 

Author Comment

by:playerone
ID: 10724551
Thanks, but I'm already using <rtexprvalue>true</rtexprvalue>, here is this tag from my tld file:
      <tag>
            <name>hashingTag</name>
            <tagclass>tags.HashingTag</tagclass>
            <attribute>
                  <name>valueToHash</name>
                  <required>true</required>
                  <rtexprvalue>true</rtexprvalue>
            </attribute>
      </tag>
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10725868
>> <tag:hashingTag valueToHash="${param.answer}" />
if you are not on a jsp2.0 server, you cannot use this as is.
let us know what server are you using?
0
 

Author Comment

by:playerone
ID: 10728115
I'm currently using Tomcat 5 (although the page may be needed to run on Tomcat 4)
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 14

Expert Comment

by:kennethxu
ID: 10728816
tomcat4 is jsp1.2, which doesn't support EL. you cannot use that in tomcat4.
if you have to do it for tomcat4, you'll need to parse the EL yourself. jakarta has a lib to do that.
let us know if your have further enquires.
0
 

Author Comment

by:playerone
ID: 10730488
Ok, i've found the commons el lib on jakarta's website, but i can't find anything about how to use it!

I've downloaded the binary and put it in the lib folder for my app but can't see what to do next.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10733416
you'll need to change your tag lib to call the el lib, I'm trying to find you some code that I did before.
0
 
LVL 14

Accepted Solution

by:
kennethxu earned 50 total points
ID: 10733895
below is a simple test tag I found in my code lib, it uses the el lib which was still old in the standard jstl1.0 implemention. before the extact it into a seperate el lib. I'm not sure how much changes they made after that, but here is the code and let me know if it doesn't make sense to you.
package com.test;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;

public class XeTestTag extends TagSupport
{
 private String messageTypeEL = "0";
 /**
  * Constructor for XeTestTag.
  */
 public XeTestTag()
 {
   super();
 }

 /**
  * Sets the messageType.
  * @param messageType The messageType to set
  */
 public void setMessageType(String messageType)
 {
   this.messageTypeEL = messageType;
   System.out.println("MessageType: " + messageType);
 }

 /**
  * Output the requested function.
  * @return int
  */
 public int doEndTag() throws JspException
 {
   String messageType = (String) ExpressionEvaluatorManager.evaluate(
         "messageType", messageTypeEL, String.class, this, pageContext );
   try
   {
    pageContext.getOut().write(messageType);
   }
   catch (java.io.IOException e)
   {
       throw new JspException("IO Error: " + e.getMessage());
   }
     return EVAL_PAGE;
 }

}
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10733956
hold on, I just had a quick look at the el lib you found in jakarta, that one seems too requires jsp 2.0, I cannot be sure.

It is a very confused in el between jsp1.2/jstl1.0 and jsp2.0/jstl1.1. I would say, if your tag is going to be end up used in tomcat 4, you should probably stick developing on tomcat 4 as well. forget about the el lib, just use the one come with jstl1.0 (standard.jar and jstl.jar) my code above works with jstl1.0.
0
 

Author Comment

by:playerone
ID: 10739306
yeah, thats done the trick!

my tags now running on Tomcat 4,

cheers!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now