Solved

JSP Custom Tag Attribute

Posted on 2004-03-31
11
1,672 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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:

690 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