0

Hi All,
I have create a custom tag to translate texts. I have to pass 3 parameters to this tag. As the parameter values are on static. I have to pass runtime expression as parameter values.I have tried various ways for this, but did not suceed. Please let me know how to achieve this.

My TLD file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
    <tlibversion>1.0</tlibversion>
    <jspversion>1.1</jspversion>
    <shortname>html</shortname>   
   <tag>
        <name>translate</name>
        <tagclass>TranslateTag</tagclass>
        <bodycontent>empty</bodycontent>
        <attribute>
                <name>key</name>
                <required>true</required>
                <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
                <name>arg0</name>
                <required>false</required>
                <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
                <name>arg1</name>
                <required>false</required>
                <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
                <name>arg2</name>
                <required>false</required>
                <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
                <name>arg3</name>
                <required>false</required>
                <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
                <name>arg4</name>
                <required>false</required>
                <rtexprvalue>true</rtexprvalue>
        </attribute>
         <attribute>
                <name>isHTML</name>
                <required>false</required>
                <rtexprvalue>true</rtexprvalue>
        </attribute>
    </tag>

My Tag handler class:

I have getter setters for arguments here

public void release() {

    super.release();

    args = null;
    key  = null;
    lang = null;
    }
 public int doStartTag() throws JspException {
    //Some processing code is written here
        // Continue processing this page
    return (SKIP_BODY);

    }

Now I am calling this tag from a JSP file :

<itc:translate key="access" arg0="<%=itemName%>"   arg1 = "<%=itemIndex%>" arg2 = <%=numOfItems%> />

Here itemName ,itemIndex and numOfItems are three variables .I want to pass variable values as parameters.But I am getting whole string "<%=itemName%>" as parameter valuse. i even tried simply with itemName an "itemName". But i did not get the variable value .

Can anyone help me here.

Thanks,

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by __avd
0

You should have to post code of Tag handler.
Example,

tag handler

package tg;

import javax.servlet.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;


public class TestTag extends TagSupport {
     String name="";
       int no=0;
     public void setName(String name) { this.name=name;}
     public String getName() { return name;}
     public void setNo(int no) { this.no=no;}
     public int getNo() { return no;}
    
     public int doStartTag() {
             try {
                   JspWriter out = pageContext.getOut();
                   out.print(no + " " + name);
              } catch(Exception ioe) {
            }
         return(SKIP_BODY);
       }
}

TLD - my.tld (Create a my.ltd under WEB-INF/ folder)

<?xml version="1.0" encoding="ISO-8859-1" ?>
<taglib>
   <tlib-version>1.0</tlib-version>
   <jsp-version>1.2</jsp-version>
   <short-name>Sample Tag</short-name>
<tag>
    <name>test</name>
    <tag-class>tg.TestTag</tag-class>
    <body-content>empty</body-content>
     <attribute>
       <name>no</name>
       <required>false</required>
       <rtexprvalue>true</rtexprvalue>
     </attribute>
     <attribute>
       <name>name</name>
       <required>false</required>
       <rtexprvalue>true</rtexprvalue>
     </attribute>
</tag>
</taglib>

Java Server Page

<%@ taglib uri="/WEB-INF/my.tld" prefix="tt"%>

<%
  int a=1;
  String name="ABC";
%>
<tt:test no="<%=a%>" name="<%=name%>" />
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.