tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MUKUNDAN PARTHASARATHY <Mukundan.Parthasara...@eng.sun.com>
Subject Re: Is it legal to have multiple taglib setter methods for the same property
Date Wed, 07 Feb 2001 17:18:23 GMT
	This is how I think Taglib attrs work:
	
	The jsp engine actually looks at your taglib class
	and figures out that it needs to call a setXXX(int)
	method because the "index" member variable is
	declared as an int.
	
	I don't know if there is an elegant way of doing
	what you want (allow an int value as well as the
	string "all") short of having *another* optional
	attribute for your Tag that has a String value...
	(and another String type member variable
	and a  corresponding setXXX(String) method in
	your taglib class).
	
	--Mukund
>Mailing-List: contact taglibs-user-help@jakarta.apache.org; run by ezmlm
>list-help: <mailto:taglibs-user-help@jakarta.apache.org>
>list-unsubscribe: <mailto:taglibs-user-unsubscribe@jakarta.apache.org>
>list-post: <mailto:taglibs-user@jakarta.apache.org>
>Delivered-To: mailing list taglibs-user@jakarta.apache.org
>Date: Tue, 06 Feb 2001 21:02:48 -0800
>From: "Alex Tang" <altitude@airflash.com>
>X-Accept-Language: en
>MIME-Version: 1.0
>To: taglibs-user@jakarta.apache.org, tomcat-dev@jakarta.apache.org
>Subject: Is it legal to have multiple taglib setter methods for the same 
property
>Content-Transfer-Encoding: 7bit
>X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N
>
>Hi folks.  (My apologies for crossposting, I wasn't sure if this is a
>taglib question or a tomcat question/problem)
>
>I'm writing a taglib using the JSP 1.1 spec (currently Tomcat 3.x). I'm
>having a problem with a property "set" method.
>
>I have a taglib tag which takes one parameter: "index".  This index can
>be either the string "all" or a number representing which CLE object to
>show.
>
>I have the following defined in my tld file:
>
>    <tag>
>        <name>displayCLE</name>
>        <tagclass>com.funkware.DisplayCLETag</tagclass>
>        <teiclass>com.funkware.DisplayCLEExtraInfo</teiclass>
>        <info>Display a CLE</info>
>        <attribute>
>            <name>index</name>
>            <required>true</required>
>            <rtexprvalue>true</rtexprvalue>
>        </attribute>
>    </tag>
>
>In my "DisplayCLETag.java" file, I have the following:
>
>
>    /**
>     * <!-- setIndex-->
>     *
>     *    Called when the taglib encounters an int for the index field...
>     *    This form takes an int which happens when a jsp expression is
>     *    evaluated on the right side of the "index=".
>     *
>     * @param nIndex
>     *    The index
>     */
>    public void setIndex ( int nIndex ) {
>        m_nIndex = nIndex;
>    }
>
>    /**
>     * <!-- setIndex-->
>     *
>     *    Called when the taglib encounters the "index" parameter.  This
>     *    form takes an object.  We try to convert and Integer and a
>     *    String.  Anything else we barf on.
>     *
>     * @param o
>     *    An object which we'll try to convert.
>     */
>    public void setIndex ( String s ) {
>        if ( SHOWELEMENT_ALL_STRING.equalsIgnoreCase ( s ) ) {
>            m_nIndex = SHOWELEMENT_ALL;
>            return;
>        }
>        try {
>            m_nIndex = Integer.parseInt ( s );
>        } catch ( NumberFormatException e ) {
>            Dispatcher.log ( Log.NOTICE, "DisplayListElementTag.setElement",
>                    "The element: '" + s +
>                    "' is invalid, it should be a number" );
>            m_nIndex = SHOWELEMENT_UNDEF;
>        }
>    }
>
>The reason I have two setter methods for Index is that doing:
>
>    <af:displayCLE index="1"/>
>
>is different than
>
>    <af:displayCLE index="<%= i %>"/> <!-- where i is an int and == 1 -->
>
>Is this a legal way of doing this?
>
>I ask because when I run tomcat using the SunJDK1.3, it works fine,
>however when I run tomcat with the SunJDK1.3 with Hotspot, it fails with
>
>     java.lang.NumberFormatException: all
>             at java.lang.Integer.parseInt(Integer.java:405)
>             at java.lang.Integer.(Integer.java:540)
>             at org.apache.jasper.runtime.JspRuntimeLibrary.convert \
>                (JspRuntimeLibrary.java:125)
>             at org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper \
>                (JspRuntimeLibrary.java:201)
>             at 
ui.html._0002fui_0002fhtml_0002fSList_0002ejspSList_jsp_3._jspService \
>                (_0002fui_0002fhtml_0002fSList_0002ejspSList_jsp_3.java:274)
>             ...
>
>I don't actually think that is hotspot related.  I think i'm doing
>something wrong.  I've looked through the tomcat code, however not too
>particularly closely.  I was hoping someone would know what's wrong.
>
>In a somewhat unrelated question, I tried having my setIndex() method
>defined as:
>
>     public void setIndex ( Object o )
>
>and then doing internal "instanceof" calls and casting to proper
>objects.  This works in Tomcat 3.1, however it fails in Tomcat 4.0.
>
>Did something change in JSP/Taglib 1.2 that makes that type of
>declaration invalid?
>
>Thanks very much.
>
>...alex...
>
>


Mime
View raw message