You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Alex Tang <al...@airflash.com> on 2001/02/07 06:02:48 UTC

Is it legal to have multiple taglib setter methods for the same property

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



Re: Is it legal to have multiple taglib setter methods for the same property

Posted by Alex Tang <al...@airflash.com>.

Maya Muchnik wrote:

> Why you cannot use only one setter "public setIndex (String index)" and then inside check if the
> string is convertable to integer or not? This way your index can represent a number or "all".

In Tocmat 3.x, your suggestion works if the tag looks like:

     <foo:displayCLE index="1"/>
     OR
     <foo:displayCLE index="all"/>

However, if the tag is used like so:

     <% int i = 1; %>
     <foo:displayCLE index="<%= i %>"/>

Tomcat tries to call "setIndex ( int i )", instead of trying to convert the int into a String.  This
results in an error in the JSP.

...alex...


>
>
> "Craig R. McClanahan" wrote:
>
> > Alex Tang wrote:
> >
> > > Thanks for the quick reply Craig.
> > >
> > > A followup question.  In tomcat 3.1, I was able to do
> > >
> > >      public setIndex ( Object o )
> > >
> > > If this is legal, I can do my own internal checking to see if the object "o" is a String or an
> > > int.  However in Tomcat 4.0, I get an error when I try to do this.  I saw some talk about this
> > > on the tomcat archives, however it wasn't clear whether this is an error on my side or an error
> > > in tomcat.
> > >
> >
> > This has been the subject of no small discussion on the expert group for JSP 1.2.  A final decision
> > is still pending AFAIK, at which time Tomcat 4.0 will change if it needs to.
> >
> > >
> > > Thanks again.
> > >
> > > ...alex...
> > >
> >
> > Craig
> >
> > >
> > > "Craig R. McClanahan" wrote:
> > >
> > > > IIRC, having two setters with different argument types violates the JavaBeans
> > > > specification.  In addition, it seems to cause the Java reflection APIs to think that there
> > > > is no setter method at all, so you will get complaints about a read-only property from any
> > > > JSP implementation that uses this technique.
> > > >
> > > > Craig McClanahan
> > > >
> > > > Alex Tang wrote:
> > > >
> > > > > 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...
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> > > For additional commands, email: tomcat-dev-help@jakarta.apache.org


Re: Is it legal to have multiple taglib setter methods for the same property

Posted by Alex Tang <al...@airflash.com>.

Maya Muchnik wrote:

> Why you cannot use only one setter "public setIndex (String index)" and then inside check if the
> string is convertable to integer or not? This way your index can represent a number or "all".

In Tocmat 3.x, your suggestion works if the tag looks like:

     <foo:displayCLE index="1"/>
     OR
     <foo:displayCLE index="all"/>

However, if the tag is used like so:

     <% int i = 1; %>
     <foo:displayCLE index="<%= i %>"/>

Tomcat tries to call "setIndex ( int i )", instead of trying to convert the int into a String.  This
results in an error in the JSP.

...alex...


>
>
> "Craig R. McClanahan" wrote:
>
> > Alex Tang wrote:
> >
> > > Thanks for the quick reply Craig.
> > >
> > > A followup question.  In tomcat 3.1, I was able to do
> > >
> > >      public setIndex ( Object o )
> > >
> > > If this is legal, I can do my own internal checking to see if the object "o" is a String or an
> > > int.  However in Tomcat 4.0, I get an error when I try to do this.  I saw some talk about this
> > > on the tomcat archives, however it wasn't clear whether this is an error on my side or an error
> > > in tomcat.
> > >
> >
> > This has been the subject of no small discussion on the expert group for JSP 1.2.  A final decision
> > is still pending AFAIK, at which time Tomcat 4.0 will change if it needs to.
> >
> > >
> > > Thanks again.
> > >
> > > ...alex...
> > >
> >
> > Craig
> >
> > >
> > > "Craig R. McClanahan" wrote:
> > >
> > > > IIRC, having two setters with different argument types violates the JavaBeans
> > > > specification.  In addition, it seems to cause the Java reflection APIs to think that there
> > > > is no setter method at all, so you will get complaints about a read-only property from any
> > > > JSP implementation that uses this technique.
> > > >
> > > > Craig McClanahan
> > > >
> > > > Alex Tang wrote:
> > > >
> > > > > 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...
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> > > For additional commands, email: tomcat-dev-help@jakarta.apache.org


Re: Is it legal to have multiple taglib setter methods for the same property

Posted by Maya Muchnik <mm...@pumatech.com>.
Why you cannot use only one setter "public setIndex (String index)" and then inside check if the
string is convertable to integer or not? This way your index can represent a number or "all".

"Craig R. McClanahan" wrote:

> Alex Tang wrote:
>
> > Thanks for the quick reply Craig.
> >
> > A followup question.  In tomcat 3.1, I was able to do
> >
> >      public setIndex ( Object o )
> >
> > If this is legal, I can do my own internal checking to see if the object "o" is a String or an
> > int.  However in Tomcat 4.0, I get an error when I try to do this.  I saw some talk about this
> > on the tomcat archives, however it wasn't clear whether this is an error on my side or an error
> > in tomcat.
> >
>
> This has been the subject of no small discussion on the expert group for JSP 1.2.  A final decision
> is still pending AFAIK, at which time Tomcat 4.0 will change if it needs to.
>
> >
> > Thanks again.
> >
> > ...alex...
> >
>
> Craig
>
> >
> > "Craig R. McClanahan" wrote:
> >
> > > IIRC, having two setters with different argument types violates the JavaBeans
> > > specification.  In addition, it seems to cause the Java reflection APIs to think that there
> > > is no setter method at all, so you will get complaints about a read-only property from any
> > > JSP implementation that uses this technique.
> > >
> > > Craig McClanahan
> > >
> > > Alex Tang wrote:
> > >
> > > > 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...
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> > For additional commands, email: tomcat-dev-help@jakarta.apache.org


Re: Is it legal to have multiple taglib setter methods for the same property

Posted by Maya Muchnik <mm...@pumatech.com>.
Why you cannot use only one setter "public setIndex (String index)" and then inside check if the
string is convertable to integer or not? This way your index can represent a number or "all".

"Craig R. McClanahan" wrote:

> Alex Tang wrote:
>
> > Thanks for the quick reply Craig.
> >
> > A followup question.  In tomcat 3.1, I was able to do
> >
> >      public setIndex ( Object o )
> >
> > If this is legal, I can do my own internal checking to see if the object "o" is a String or an
> > int.  However in Tomcat 4.0, I get an error when I try to do this.  I saw some talk about this
> > on the tomcat archives, however it wasn't clear whether this is an error on my side or an error
> > in tomcat.
> >
>
> This has been the subject of no small discussion on the expert group for JSP 1.2.  A final decision
> is still pending AFAIK, at which time Tomcat 4.0 will change if it needs to.
>
> >
> > Thanks again.
> >
> > ...alex...
> >
>
> Craig
>
> >
> > "Craig R. McClanahan" wrote:
> >
> > > IIRC, having two setters with different argument types violates the JavaBeans
> > > specification.  In addition, it seems to cause the Java reflection APIs to think that there
> > > is no setter method at all, so you will get complaints about a read-only property from any
> > > JSP implementation that uses this technique.
> > >
> > > Craig McClanahan
> > >
> > > Alex Tang wrote:
> > >
> > > > 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...
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> > For additional commands, email: tomcat-dev-help@jakarta.apache.org


Re: Is it legal to have multiple taglib setter methods for the same property

Posted by Pierre Delisle <pi...@sun.com>.
Alex,

Until the expert group rules on this, one workaround (that will always work)
is to simply do the following (assuming a property of type Object):

    instead of:
        <mytags:foo bar="abc"/>
    use:
        <mytags:foo bar='<%="abc"%>'/>

Another way is to define a PropertyEditor associated with your
property of type Object.

As Craig mentioned, this problem has been the subject of numerous
discussions. Here are some pointers that may help you and others
understand the issue.

http://www.mail-archive.com/tomcat-dev@jakarta.apache.org/msg00732.html
http://www.mail-archive.com/tomcat-dev@jakarta.apache.org/msg01323.html
http://www.mail-archive.com/tomcat-dev@jakarta.apache.org/msg01328.html

    -- Pierre

"Craig R. McClanahan" wrote:
> 
> Alex Tang wrote:
> 
> > Thanks for the quick reply Craig.
> >
> > A followup question.  In tomcat 3.1, I was able to do
> >
> >      public setIndex ( Object o )
> >
> > If this is legal, I can do my own internal checking to see if the object "o" is a String or an
> > int.  However in Tomcat 4.0, I get an error when I try to do this.  I saw some talk about this
> > on the tomcat archives, however it wasn't clear whether this is an error on my side or an error
> > in tomcat.
> >
> 
> This has been the subject of no small discussion on the expert group for JSP 1.2.  A final decision
> is still pending AFAIK, at which time Tomcat 4.0 will change if it needs to.
> 
> >
> > Thanks again.
> >
> > ...alex...
> >
> 
> Craig
> 
> >
> > "Craig R. McClanahan" wrote:
> >
> > > IIRC, having two setters with different argument types violates the JavaBeans
> > > specification.  In addition, it seems to cause the Java reflection APIs to think that there
> > > is no setter method at all, so you will get complaints about a read-only property from any
> > > JSP implementation that uses this technique.
> > >
> > > Craig McClanahan
> > >
> > > Alex Tang wrote:
> > >
> > > > 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...
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> > For additional commands, email: tomcat-dev-help@jakarta.apache.org

Re: Is it legal to have multiple taglib setter methods for the same property

Posted by Pierre Delisle <pi...@sun.com>.
Alex,

Until the expert group rules on this, one workaround (that will always work)
is to simply do the following (assuming a property of type Object):

    instead of:
        <mytags:foo bar="abc"/>
    use:
        <mytags:foo bar='<%="abc"%>'/>

Another way is to define a PropertyEditor associated with your
property of type Object.

As Craig mentioned, this problem has been the subject of numerous
discussions. Here are some pointers that may help you and others
understand the issue.

http://www.mail-archive.com/tomcat-dev@jakarta.apache.org/msg00732.html
http://www.mail-archive.com/tomcat-dev@jakarta.apache.org/msg01323.html
http://www.mail-archive.com/tomcat-dev@jakarta.apache.org/msg01328.html

    -- Pierre

"Craig R. McClanahan" wrote:
> 
> Alex Tang wrote:
> 
> > Thanks for the quick reply Craig.
> >
> > A followup question.  In tomcat 3.1, I was able to do
> >
> >      public setIndex ( Object o )
> >
> > If this is legal, I can do my own internal checking to see if the object "o" is a String or an
> > int.  However in Tomcat 4.0, I get an error when I try to do this.  I saw some talk about this
> > on the tomcat archives, however it wasn't clear whether this is an error on my side or an error
> > in tomcat.
> >
> 
> This has been the subject of no small discussion on the expert group for JSP 1.2.  A final decision
> is still pending AFAIK, at which time Tomcat 4.0 will change if it needs to.
> 
> >
> > Thanks again.
> >
> > ...alex...
> >
> 
> Craig
> 
> >
> > "Craig R. McClanahan" wrote:
> >
> > > IIRC, having two setters with different argument types violates the JavaBeans
> > > specification.  In addition, it seems to cause the Java reflection APIs to think that there
> > > is no setter method at all, so you will get complaints about a read-only property from any
> > > JSP implementation that uses this technique.
> > >
> > > Craig McClanahan
> > >
> > > Alex Tang wrote:
> > >
> > > > 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...
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> > For additional commands, email: tomcat-dev-help@jakarta.apache.org

Re: Is it legal to have multiple taglib setter methods for the same property

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Alex Tang wrote:

> Thanks for the quick reply Craig.
>
> A followup question.  In tomcat 3.1, I was able to do
>
>      public setIndex ( Object o )
>
> If this is legal, I can do my own internal checking to see if the object "o" is a String or an
> int.  However in Tomcat 4.0, I get an error when I try to do this.  I saw some talk about this
> on the tomcat archives, however it wasn't clear whether this is an error on my side or an error
> in tomcat.
>

This has been the subject of no small discussion on the expert group for JSP 1.2.  A final decision
is still pending AFAIK, at which time Tomcat 4.0 will change if it needs to.

>
> Thanks again.
>
> ...alex...
>

Craig


>
> "Craig R. McClanahan" wrote:
>
> > IIRC, having two setters with different argument types violates the JavaBeans
> > specification.  In addition, it seems to cause the Java reflection APIs to think that there
> > is no setter method at all, so you will get complaints about a read-only property from any
> > JSP implementation that uses this technique.
> >
> > Craig McClanahan
> >
> > Alex Tang wrote:
> >
> > > 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...
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, email: tomcat-dev-help@jakarta.apache.org


Re: Is it legal to have multiple taglib setter methods for the same property

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Alex Tang wrote:

> Thanks for the quick reply Craig.
>
> A followup question.  In tomcat 3.1, I was able to do
>
>      public setIndex ( Object o )
>
> If this is legal, I can do my own internal checking to see if the object "o" is a String or an
> int.  However in Tomcat 4.0, I get an error when I try to do this.  I saw some talk about this
> on the tomcat archives, however it wasn't clear whether this is an error on my side or an error
> in tomcat.
>

This has been the subject of no small discussion on the expert group for JSP 1.2.  A final decision
is still pending AFAIK, at which time Tomcat 4.0 will change if it needs to.

>
> Thanks again.
>
> ...alex...
>

Craig


>
> "Craig R. McClanahan" wrote:
>
> > IIRC, having two setters with different argument types violates the JavaBeans
> > specification.  In addition, it seems to cause the Java reflection APIs to think that there
> > is no setter method at all, so you will get complaints about a read-only property from any
> > JSP implementation that uses this technique.
> >
> > Craig McClanahan
> >
> > Alex Tang wrote:
> >
> > > 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...
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, email: tomcat-dev-help@jakarta.apache.org


Re: Is it legal to have multiple taglib setter methods for the same property

Posted by Alex Tang <al...@airflash.com>.
Thanks for the quick reply Craig.

A followup question.  In tomcat 3.1, I was able to do

     public setIndex ( Object o )

If this is legal, I can do my own internal checking to see if the object "o" is a String or an
int.  However in Tomcat 4.0, I get an error when I try to do this.  I saw some talk about this
on the tomcat archives, however it wasn't clear whether this is an error on my side or an error
in tomcat.

Thanks again.

...alex...

"Craig R. McClanahan" wrote:

> IIRC, having two setters with different argument types violates the JavaBeans
> specification.  In addition, it seems to cause the Java reflection APIs to think that there
> is no setter method at all, so you will get complaints about a read-only property from any
> JSP implementation that uses this technique.
>
> Craig McClanahan
>
> Alex Tang wrote:
>
> > 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...


Re: Is it legal to have multiple taglib setter methods for the same property

Posted by Alex Tang <al...@airflash.com>.
Thanks for the quick reply Craig.

A followup question.  In tomcat 3.1, I was able to do

     public setIndex ( Object o )

If this is legal, I can do my own internal checking to see if the object "o" is a String or an
int.  However in Tomcat 4.0, I get an error when I try to do this.  I saw some talk about this
on the tomcat archives, however it wasn't clear whether this is an error on my side or an error
in tomcat.

Thanks again.

...alex...

"Craig R. McClanahan" wrote:

> IIRC, having two setters with different argument types violates the JavaBeans
> specification.  In addition, it seems to cause the Java reflection APIs to think that there
> is no setter method at all, so you will get complaints about a read-only property from any
> JSP implementation that uses this technique.
>
> Craig McClanahan
>
> Alex Tang wrote:
>
> > 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...


Re: newbie: why isn't jsp variable initialized?

Posted by "David M. Karr" <dk...@tcsi.com>.
>>>>> "Robert" == Robert Karen <ro...@yahoo.com> writes:
  Robert> Thanks. It worked. Could you give me a brief
  Robert> explanation? I guess the '<%' is dynamic while
  Robert> the <%! declaration is not. Is it part of the specs
  Robert> that Jsp variables are stored session to session?

The easy way to look at this (because that's exactly how it works), is
that "<%!" places the piece of code outside of the service method,
inside the class, but "<%" gets placed inside the service method
itself.

The result is that ordinary variables declared with "<%!" become
INSTANCE variables (not static as one person indicated), and variables
declared with "<%" become local variables of the service method.

So, when the servlet engine creates an instance of your servlet, the
instance variable will live ACROSS invocations of the servlet, but the
local variable will be reinitialized on every invocation.

If you have an instance variable that gets incremented every time you
invoke the servlet, then it will increase by one for every
invocation.  A local variable will not increment each time.

-- 
===================================================================
David M. Karr     ; w:(425)487-8312     ; TCSI & Best Consulting
dkarr@tcsi.com    ; Java/Unix/XML/C++/X ; BrainBench CJ12P (#12004)


Re: newbie: why isn't jsp variable initialized?

Posted by Robert Karen <ro...@yahoo.com>.
Thanks. It worked. Could you give me a brief
explanation? I guess the '<%' is dynamic while
the <%! declaration is not. Is it part of the specs
that Jsp variables are stored session to session?

Thanks again for your time.

Robert Karen 
--- Pierre Delisle <pi...@sun.com> wrote:
> Replace 
>   <%! int myline = 1; %>  [declaration]
> with 
>   <% int myline = 1; %>   [scriptlet]
> 
>     -- Pierre
> 
> Robert Karen wrote:
> > 
> > I've been experimenting with <sql> taglib and a
> > taglib I created to parse results. I found that
> > when I call the jsp file again (from an html form)
> > that a new database connection is opened (I want
> > this), but the line numbers (scriptlet variable
> > myline)
> > start counting from where they remained
> > the last time I ran saw the page. Why isn't it
> being
> > initialized again in each page? I'm using Tomcat
> 3.2.
> > Thanks for any help.
> > 
> > Robert Karen
> > Here is the file:
> > 
> > <%@ taglib uri="/WEB-INF/sql.tld" prefix="sql" %>
> > <%@ taglib uri="/WEB-INF/bldinserttag.tld"
> > prefix="trackerSansDb"%>
> > <html>
> > <head>
> > <title>Examples of JSPSPEC SQL Tag Library Tag
> > Usage</title>
> > </head>
> > <body bgcolor="white">
> > 
> > <sql:connection id="conn1" >
> >   <sql:dburl><%= request.getParameter("dburl")
> > %></sql:dburl>
> >   <sql:driver><%= request.getParameter("driver")
> > %></sql:driver>
> >   <sql:userid><%= request.getParameter("userid")
> > %></sql:userid>
> >   <sql:password><%=
> request.getParameter("password")
> > %></sql:password>
> > </sql:connection>
> > 
> > <trackerSansDb:showAllResSet dataSet="mydata">
> >   <sql:query id="getBoxen" connection="conn1"
> > visibility="table">
> >     select userid || '|' ||
> >       pageid || '|' ||
> >       to_char (timeviewed, 'MON DD, YYYY
> HH:MI:SS') ||
> > '|' ||
> >       client_address || '|' ||
> >       sessionid
> >       from user_pages_viewed
> >       order by userid , timeviewed
> >   </sql:query>
> > </trackerSansDb:showAllResSet>
> > <%--
> >   -- close the connection or it doesn't get closed
> > until oracle times it out.
> >   --%>
> > <%@ page import="java.io.IOException, java.sql.*"
> %>
> > <% try {conn1.close();%>
> >     <br><h2>CLOSING CONNECTION FROM
> > SCRIPTLET.<br></h2>
> > <%  } catch (SQLException e) {%>
> >     <br><h2>UNABLE TO CLOSE CONNECTION.<br></h2>
> >   <% }  %>
> > <table border="1" align="left">
> > <%-- showAllLoop gets data from mydata (ArrayList
> page
> > attribute) --%>
> > <%! int myline = 1; %>
> > <trackerSansDb:showAllLoop dataSet="mydata">
> >   <tr>
> >      <%-- showCols gets 1 row from
> > findAncestorWithClass().getCurrentRow --%>
> >      <td align="right">
> >        <%=myline%>
> >        <% myline++; %>
> > <% try {conn1.close();%>
> >     <br><h2>CLOSING CONNECTION FROM
> > SCRIPTLET.<br></h2>
> > <%  } catch (SQLException e) {%>
> >     <br><h2>UNABLE TO CLOSE CONNECTION.<br></h2>
> >   <% }  %>
> > <table border="1" align="left">
> > <%-- showAllLoop gets data from mydata (ArrayList
> page
> > attribute) --%>
> > <%! int myline = 1; %>
> > <trackerSansDb:showAllLoop dataSet="mydata">
> >   <tr>
> >      <%-- showCols gets 1 row from
> > findAncestorWithClass().getCurrentRow --%>
> >      <td align="right">
> >        <%=myline%>
> >        <% myline++; %>
> >      </td>
> >      <trackerSansDb:showCols id="row" >
> >        <td><jsp:getProperty name="row"
> > property="currentCol"/></td>
> >      </trackerSansDb:showCols>
> >   </tr>
> > </trackerSansDb:showAllLoop>
> > </table>
> > </body>
> > </html>
> > 
> > __________________________________________________
> > Do You Yahoo!?
> > Get personalized email addresses from Yahoo! Mail
> - only $35
> > a year!  http://personal.mail.yahoo.com


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/

Re: newbie: why isn't jsp variable initialized?

Posted by Pierre Delisle <pi...@sun.com>.
Replace 
  <%! int myline = 1; %>  [declaration]
with 
  <% int myline = 1; %>   [scriptlet]

    -- Pierre

Robert Karen wrote:
> 
> I've been experimenting with <sql> taglib and a
> taglib I created to parse results. I found that
> when I call the jsp file again (from an html form)
> that a new database connection is opened (I want
> this), but the line numbers (scriptlet variable
> myline)
> start counting from where they remained
> the last time I ran saw the page. Why isn't it being
> initialized again in each page? I'm using Tomcat 3.2.
> Thanks for any help.
> 
> Robert Karen
> Here is the file:
> 
> <%@ taglib uri="/WEB-INF/sql.tld" prefix="sql" %>
> <%@ taglib uri="/WEB-INF/bldinserttag.tld"
> prefix="trackerSansDb"%>
> <html>
> <head>
> <title>Examples of JSPSPEC SQL Tag Library Tag
> Usage</title>
> </head>
> <body bgcolor="white">
> 
> <sql:connection id="conn1" >
>   <sql:dburl><%= request.getParameter("dburl")
> %></sql:dburl>
>   <sql:driver><%= request.getParameter("driver")
> %></sql:driver>
>   <sql:userid><%= request.getParameter("userid")
> %></sql:userid>
>   <sql:password><%= request.getParameter("password")
> %></sql:password>
> </sql:connection>
> 
> <trackerSansDb:showAllResSet dataSet="mydata">
>   <sql:query id="getBoxen" connection="conn1"
> visibility="table">
>     select userid || '|' ||
>       pageid || '|' ||
>       to_char (timeviewed, 'MON DD, YYYY HH:MI:SS') ||
> '|' ||
>       client_address || '|' ||
>       sessionid
>       from user_pages_viewed
>       order by userid , timeviewed
>   </sql:query>
> </trackerSansDb:showAllResSet>
> <%--
>   -- close the connection or it doesn't get closed
> until oracle times it out.
>   --%>
> <%@ page import="java.io.IOException, java.sql.*" %>
> <% try {conn1.close();%>
>     <br><h2>CLOSING CONNECTION FROM
> SCRIPTLET.<br></h2>
> <%  } catch (SQLException e) {%>
>     <br><h2>UNABLE TO CLOSE CONNECTION.<br></h2>
>   <% }  %>
> <table border="1" align="left">
> <%-- showAllLoop gets data from mydata (ArrayList page
> attribute) --%>
> <%! int myline = 1; %>
> <trackerSansDb:showAllLoop dataSet="mydata">
>   <tr>
>      <%-- showCols gets 1 row from
> findAncestorWithClass().getCurrentRow --%>
>      <td align="right">
>        <%=myline%>
>        <% myline++; %>
> <% try {conn1.close();%>
>     <br><h2>CLOSING CONNECTION FROM
> SCRIPTLET.<br></h2>
> <%  } catch (SQLException e) {%>
>     <br><h2>UNABLE TO CLOSE CONNECTION.<br></h2>
>   <% }  %>
> <table border="1" align="left">
> <%-- showAllLoop gets data from mydata (ArrayList page
> attribute) --%>
> <%! int myline = 1; %>
> <trackerSansDb:showAllLoop dataSet="mydata">
>   <tr>
>      <%-- showCols gets 1 row from
> findAncestorWithClass().getCurrentRow --%>
>      <td align="right">
>        <%=myline%>
>        <% myline++; %>
>      </td>
>      <trackerSansDb:showCols id="row" >
>        <td><jsp:getProperty name="row"
> property="currentCol"/></td>
>      </trackerSansDb:showCols>
>   </tr>
> </trackerSansDb:showAllLoop>
> </table>
> </body>
> </html>
> 
> __________________________________________________
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail - only $35
> a year!  http://personal.mail.yahoo.com/

newbie: why isn't jsp variable initialized?

Posted by Robert Karen <ro...@yahoo.com>.
I've been experimenting with <sql> taglib and a 
taglib I created to parse results. I found that
when I call the jsp file again (from an html form)
that a new database connection is opened (I want
this), but the line numbers (scriptlet variable
myline) 
start counting from where they remained
the last time I ran saw the page. Why isn't it being 
initialized again in each page? I'm using Tomcat 3.2.
Thanks for any help.

Robert Karen
Here is the file:

<%@ taglib uri="/WEB-INF/sql.tld" prefix="sql" %>
<%@ taglib uri="/WEB-INF/bldinserttag.tld"
prefix="trackerSansDb"%>
<html>
<head>
<title>Examples of JSPSPEC SQL Tag Library Tag
Usage</title>
</head>
<body bgcolor="white">

<sql:connection id="conn1" >
  <sql:dburl><%= request.getParameter("dburl")
%></sql:dburl>
  <sql:driver><%= request.getParameter("driver")
%></sql:driver>
  <sql:userid><%= request.getParameter("userid")
%></sql:userid>
  <sql:password><%= request.getParameter("password")
%></sql:password>
</sql:connection>

<trackerSansDb:showAllResSet dataSet="mydata">
  <sql:query id="getBoxen" connection="conn1"
visibility="table">
    select userid || '|' ||  
      pageid || '|' || 
      to_char (timeviewed, 'MON DD, YYYY HH:MI:SS') ||
'|' ||
      client_address || '|' ||
      sessionid 
      from user_pages_viewed
      order by userid , timeviewed
  </sql:query>
</trackerSansDb:showAllResSet>
<%-- 
  -- close the connection or it doesn't get closed
until oracle times it out.
  --%>
<%@ page import="java.io.IOException, java.sql.*" %>
<% try {conn1.close();%>
    <br><h2>CLOSING CONNECTION FROM
SCRIPTLET.<br></h2>
<%  } catch (SQLException e) {%>
    <br><h2>UNABLE TO CLOSE CONNECTION.<br></h2>
  <% }  %>
<table border="1" align="left">
<%-- showAllLoop gets data from mydata (ArrayList page
attribute) --%>
<%! int myline = 1; %>
<trackerSansDb:showAllLoop dataSet="mydata">
  <tr>
     <%-- showCols gets 1 row from
findAncestorWithClass().getCurrentRow --%>
     <td align="right">
       <%=myline%>
       <% myline++; %>
<% try {conn1.close();%>
    <br><h2>CLOSING CONNECTION FROM
SCRIPTLET.<br></h2>
<%  } catch (SQLException e) {%>
    <br><h2>UNABLE TO CLOSE CONNECTION.<br></h2>
  <% }  %>
<table border="1" align="left">
<%-- showAllLoop gets data from mydata (ArrayList page
attribute) --%>
<%! int myline = 1; %>
<trackerSansDb:showAllLoop dataSet="mydata">
  <tr>
     <%-- showCols gets 1 row from
findAncestorWithClass().getCurrentRow --%>
     <td align="right">
       <%=myline%>
       <% myline++; %>
     </td>
     <trackerSansDb:showCols id="row" >
       <td><jsp:getProperty name="row"
property="currentCol"/></td>
     </trackerSansDb:showCols>
  </tr>
</trackerSansDb:showAllLoop>
</table>
</body>
</html>


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/

Re: Is it legal to have multiple taglib setter methods for the same property

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
IIRC, having two setters with different argument types violates the JavaBeans
specification.  In addition, it seems to cause the Java reflection APIs to think that there
is no setter method at all, so you will get complaints about a read-only property from any
JSP implementation that uses this technique.

Craig McClanahan

Alex Tang wrote:

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


Re: Is it legal to have multiple taglib setter methods for the same property

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
IIRC, having two setters with different argument types violates the JavaBeans
specification.  In addition, it seems to cause the Java reflection APIs to think that there
is no setter method at all, so you will get complaints about a read-only property from any
JSP implementation that uses this technique.

Craig McClanahan

Alex Tang wrote:

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