> Andy,
>
> Is there any reason that you would want to put this into the
> doStartTag() method instead of a static initializer?

There is often a big difference in the readability errors from
initializers as opposed to checked exceptions from a tag;
initializer errors get wrapped (and masked) in an
ExceptionInInitializerError.  Leaving it in doStartTag() is
more likely to produce a readable error (which is why we are
doing the check in the first place).

Note that this will NOT help wrt to the example pages, since
ListObject is being instantiated above the tag.  Maybe the
example pages' init.jsp could call the checkCommonsLang() direcly?


(LONG)
Here's a comparison using the following method (improved from previous
email):

    static boolean commonsLangChecked = false;
    /**
     * Displaytag requires commons-lang 2.x or better; it is not compatible
with earlier versions.
     * @throws JspTagException if the wrong library, or no library at all,
is found.
     */
    static void checkCommonsLang() throws JspTagException{
        if ( commonsLangChecked ) {return;}
                try
        {  // Do they have commons lang ?
            Class stringUtils =
Class.forName("org.apache.commons.lang.StringUtils");
            try
            {
                // this method is new in commons-lang 2.0
                stringUtils.getMethod("capitalize",  new Class[]{
String.class} );
            }
            catch (NoSuchMethodException ee)
            {
                throw new JspTagException("\n\nYou appear to have an
INCOMPATIBLE VERSION of the Commons Lang library.  \n" +
                        "Displaytag requires version 2 of this library, and
you appear to have a prior version in your \n" +
                        "classpath.  You must remove this prior version AND
ensure that ONLY version 2 is in your classpath.\n " +
                        "If commons-lang-1.x is in your classpath, be sure
to remove it. \n" +
                        "Be sure to delete all cached or temporary jar files
from your application server; Tomcat users \n" +
                        "should be sure to also check the
CATALINA_HOME/shared folder; you may need to restart the server. \n" +
                        "commons-lang-2.jar is available in the displaytag
distribution, or from the Jakarta website at \n" +
                        "http://jakarta.apache.org/commons \n\n.");
            }
        }
        catch (ClassNotFoundException e)
        {
            throw new JspTagException("You do not appear to have the Commons
Lang library, version 2.  " +
                    "commons-lang-2.jar is available in the displaytag
distribution, or from the Jakarta website at " +
                    "http://jakarta.apache.org/commons .  ");
        }
        commonsLangChecked=true;
    }


Calling that method from a static initializer :
    static {
        try
        {
            checkCommonsLang();
        }
        catch (JspTagException e)
        {
            throw new RuntimeException(e.getMessage());
        }
    }


produces a nasty error page in tomcat 5 (although a decent message is in the
logfiles):

type Exception report

message

description The server encountered an internal error () that prevented it
from fulfilling this request.

exception

javax.servlet.ServletException
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:256)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

root cause

java.lang.ExceptionInInitializerError
        java.lang.Class.forName0(Native Method)
        java.lang.Class.forName(Class.java:141)

org.displaytag.util.BeanInfoUtil.getPropertyDescriptors(BeanInfoUtil.java:54
)
        java.beans.Introspector.getTargetPropertyInfo(Introspector.java:459)
        java.beans.Introspector.getBeanInfo(Introspector.java:372)
        java.beans.Introspector.getBeanInfo(Introspector.java:144)
        org.apache.jasper.compiler.Generator$TagHandlerInfo.(Generator.java:3633)

org.apache.jasper.compiler.Generator$GenerateVisitor.getTagHandlerInfo(Gener
ator.java:2079)

org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:15
98)
        org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1457)
        org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2156)
        org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2206)
        org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2212)
        org.apache.jasper.compiler.Node$Root.accept(Node.java:484)
        org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2156)
        org.apache.jasper.compiler.Generator.generate(Generator.java:3228)
        org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:284)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:437)

org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:5
55)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:2
91)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


Calling the check from the doStartTag() produces:
type Exception report

message

description The server encountered an internal error () that prevented it
from fulfilling this request.

exception

javax.servlet.ServletException:

You appear to have an INCOMPATIBLE VERSION of the Commons Lang library.
Displaytag requires version 2 of this library, and you appear to have a
prior version in your
classpath.  You must remove this prior version AND ensure that ONLY version
2 is in your classpath.
 If commons-lang-1.x is in your classpath, be sure to remove it.
Be sure to delete all cached or temporary jar files from your application
server; Tomcat users
should be sure to also check the CATALINA_HOME/shared folder; you may need
to restart the server.
commons-lang-2.jar is available in the displaytag distribution, or from the
Jakarta website at
http://jakarta.apache.org/commons

.

org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImp
l.java:673)

org.apache.jsp.example_002dstyles_jsp._jspService(example_002dstyles_jsp.jav
a:384)
        org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:3
11)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

root cause

etc.

>
> Ben
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Andy
> Pruitt
> Sent: Thursday, October 23, 2003 12:08 PM
> To: [EMAIL PROTECTED]
> Subject: [PATCH ] RE: [displaytag-devel] [ displaytag-Bugs-828341 ]
> Struts 1.1 / display Tag
>
>
> Seems like we get a lot of these configuration errors in the bug
> reports; the error
> is admittedly a bit obscure.
>
> This patch may reduce the confusion somewhat:
>
>
> public TableTag(){
>     public int doStartTag() throws JspException {
>         try {  // this class is new in commons-lang 2.0
>             Class.forName("org.apache.commons.lang.WordUtils");
>         } catch(ClassNotFoundException e){
>             try {
>                 Class.forName("org.apache.commons.lang.enum.Enum");
>                 throw new JspTagException("\n\nYou appear to have an
> INCOMPATIBLE VERSION of the Commons Lang library.  " +
>                         "Displaytag requires version 2 of this library,
> and you appear to have a prior version in your " +
>                         "classpath.  You must remove this prior version
> and ensure that only version 2 is in your classpath. " +
>                         "Be sure to delete all cached or temporary jar
> files from your application server; Tomcat users " +
>                         "should be sure to also check the
> CATALINA_HOME/shared folder; you may need to restart the server. " +
>                         "commons-lang-2.jar is available in the
> displaytag distribution, or from the Jakarta website at " +
>                         "http://jakarta.apache.org/commons \n\n.");
>             } catch (ClassNotFoundException ee ){
>                 throw new JspTagException("You do not appear to have the
> Commons Lang library, version 2.  " +
>                     "commons-lang-2.jar is available in the displaytag
> distribution, or from the Jakarta website at " +
>                     "http://jakarta.apache.org/commons .  ");
>             }
>         }
>         // continue with the method.
>     }
> }
>
>
> > -----Original Message-----
> > From: SourceForge.net [mailto:[EMAIL PROTECTED]
> > Sent: Thursday, October 23, 2003 8:17 AM
> > To: [EMAIL PROTECTED]
> > Subject: [displaytag-devel] [ displaytag-Bugs-828341 ] Struts
> > 1.1 / display Tag
> >
> >
> > Bugs item #828341, was opened at 2003-10-22 16:32
> > Message generated for change (Comment added) made by
> > abhijit_neogy You can respond by visiting:
> > https://sourceforge.net/tracker/?func=detail&atid=536613&aid=8
> > 28341&group_id=73068
> >
> > Category: main tag library
> > Group: v 1.0-b1
> > Status: Open
> > Resolution: None
> > Priority: 5
> > Submitted By: abhijit neogy (abhijit_neogy)
> > Assigned to: Nobody/Anonymous (nobody)
> > Summary: Struts 1.1 / display Tag
> >
> > Initial Comment:
> > The struts Action servlet forwards a JSP which inturn
> > uses the tag <display:table>
> >
> > <display:table> works fine if I call the struts Action
> > servet directly from browser
> > Eg# http://someURL/mytest.do
> >
> > But if I call the same Action servlet from a form
> > EG# <html:form action="/mytest.do"> the same JSP
> > throws exception after org.display.tags.TagTable=
> > doStartTag().
> >
> > The exception is:java.lang.Exception:
> > org/apache/commons/lang/StringEscapeUtils
> >
> > Any suggestion ?? The Action servlet, The Data being
> > forwarded in ArrayList and the JSP is the same. Only
> > difference in how the Action servlet is being called.
> >
> > Thanks
> > Abhijit
> >
> >
> > ----------------------------------------------------------------------
> >
> > >Comment By: abhijit neogy (abhijit_neogy)
> > Date: 2003-10-23 13:16
> >
> > Message:
> > Logged In: YES
> > user_id=892491
> >
> > if the HTML Form calling the Action servlet (which forwards
> > a JSP with <display:table>) has struts tag <html:text> then
> > the <display:table> in the forwarded JSP throws Exception:
> > org/apache/commons/lang/StringEscapeUtils
> >
> > But if in the HTML Form <input type="text"> is used insted of
> > <html:text> then the <display:table> tags works fine
> >
> >
> > /**********************************************
> > *******
> > If this is the Form calling the Action Servlet
> > Which inturn returns the JSP containing <display:table>
> > tag . Then <display:table> in the returned JSP works
> > **********************************************
> > ******/
> > <html:form action="/view.do">
> > <Input type="text" property="caller" />
> > <html:submit />
> > </html:form>
> >
> >
> > /**********************************************
> > ********
> > if <input type="text" is replaced by <html:text>
> > then the returned JSP containig <display:propert>
> > throws Exception
> > **********************************************
> > *******/
> > <html:form action="/view.do">
> > <html:text property="caller" />
> > <html:submit />
> > </html:form>
> >
> >
> > ----------------------------------------------------------------------
> >
> > You can respond by visiting:
> > https://sourceforge.net/tracker/?func=detail&atid=536613&aid=8
> 28341&group_id=73068
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by OSDN developer relations Here's your
> chance to show off your extensive product knowledge We want to know what
> you know. Tell us and you have a chance to win $100
> http://www.zoomerang.com/survey.zgi?HRPT1X3RYQNC5V4MLNSV3E54
> _______________________________________________
> displaytag-devel mailing list [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/displaytag-devel
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: The SF.net Donation Program.
> Do you like what SourceForge.net is doing for the Open
> Source Community?  Make a contribution, and help us add new
> features and functionality. Click here: http://sourceforge.net/donate/
> _______________________________________________
> displaytag-devel mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/displaytag-devel
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: The SF.net Donation Program.
> Do you like what SourceForge.net is doing for the Open
> Source Community?  Make a contribution, and help us add new
> features and functionality. Click here: http://sourceforge.net/donate/
> _______________________________________________
> displaytag-devel mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/displaytag-devel



-------------------------------------------------------
This SF.net email is sponsored by: The SF.net Donation Program.
Do you like what SourceForge.net is doing for the Open
Source Community?  Make a contribution, and help us add new
features and functionality. Click here: http://sourceforge.net/donate/
_______________________________________________
displaytag-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/displaytag-devel

Reply via email to