[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

JSP Custom Tag Attribute

Posted on 2004-03-31
11
Medium Priority
?
1,678 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 
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 200 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
The viewer will learn how to count occurrences of each item in an array.

650 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