?
Solved

JSP Custom Tag Attribute

Posted on 2004-03-31
11
Medium Priority
?
1,675 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
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

765 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