Solved

JSP Custom Tag Attribute

Posted on 2004-03-31
11
1,659 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

706 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

18 Experts available now in Live!

Get 1:1 Help Now