You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Mohammed Bustany <mb...@lavastorm.com> on 2000/12/02 02:37:15 UTC

Q: Can I pass an array of type String to a tag lib

Or does it only accept String?

If it does accept an array, does it need any special conversion
inside the set method?

Please respond directly to my email address
since I'm not subscribed to the mailing list.

Thank you

Mohammed
LavaStorm, Inc.

==================== EXAMPLE  ========================

public class options
{
    private String selectedoption;
    private String[] optionsList;

    public void setOptionsList(String[] list)
    {
        optionsList = list;
    }

    ........ body of the tag here .......

}


------- jsp file:

<%! String[] list = { "January", "February", "March" }; %>

<lava:listit  selectedoption="1" optionsList="list">
.....
.....
</lava>

Re: Q: Can I pass an array of type String to a tag lib

Posted by Hans Bergsten <ha...@gefionsoftware.com>.
Mohammed Bustany wrote:
> 
> Thanks Craig.  It worked.  I was missing the
> <%= %> like you suggested.
> 
> Maybe I can ask you another related question.  I've
> already tried many different things but still can't
> get it to work.
> 
> I'm using Tomcat 3.1  

Even though it's not related to this error, I suggest you
upgrade to Tomcat 3.2. A lot of bugs have been fixed and
a lot of enhancements have been made since 3.1.

> When I place the .tld file
> (i.e., lava.tld) and the related .jsp file in
> the ROOT directory as well as the applicable
> .class files in the ROOT/WEB-INF/classes directory,
> the jsp works great.  However, when I tried to have
> them work in another war directory, it doesn't.
> I get the exception below.  It just doesn't make
> sense why it would complain about the web.xml file!!!
> [...]
> org.apache.jasper.JasperException: Unable to open taglibrary lava.tld :
> Parse Error in the tag library descriptor: Element "web-app" does not allow
> "servlet" here.
> [...]

This means that the web.xml file has a <servlet> element in the wrong
place. The order of the elements is significant. Look at the web.xml
DTD in the Servlet 2.2 spec to see the order they must be listed in.
The reason this problem is not caught earlier is that Tomcat 3.1
doesn't validate the web.xml file on start-up (3.2 does), so it's not
until the JSP container tries to read web.xml to find <tag-library>
elements that it's found.

Hans
-- 
Hans Bergsten		hans@gefionsoftware.com
Gefion Software		http://www.gefionsoftware.com

RE: Q: Can I pass an array of type String to a tag lib

Posted by Mohammed Bustany <mb...@lavastorm.com>.
Thanks Craig.  It worked.  I was missing the
<%= %> like you suggested.

Maybe I can ask you another related question.  I've
already tried many different things but still can't
get it to work.

I'm using Tomcat 3.1  When I place the .tld file
(i.e., lava.tld) and the related .jsp file in
the ROOT directory as well as the applicable
.class files in the ROOT/WEB-INF/classes directory,
the jsp works great.  However, when I tried to have
them work in another war directory, it doesn't.
I get the exception below.  It just doesn't make
sense why it would complain about the web.xml file!!!
I seems that tomcat requires an entry in web.xml file
of the war application.  I'm going thru the specs
to figure that out.  It's probably related
to not being able to find the .tld file even though
it's readily accessible.  If you can shed some light
on this problem, I would appreciate it.

One more thing, I've replaced the /servlet with /iwork
in the server.xml file.

I've attached all applicable files.

Thank you very much for your help.

Mohammed


====================================================
Error: 500
Location: /iwork/options.jsp
Internal Servlet Error:

org.apache.jasper.JasperException: Unable to open taglibrary lava.tld :
Parse Error in the tag library descriptor: Element "web-app" does not allow
"servlet" here.
	at
org.apache.jasper.compiler.JspParseEventListener.handleDirective(JspParseEve
ntListener.java:672)
	at
org.apache.jasper.compiler.DelegatingListener.handleDirective(DelegatingList
ener.java:116)
	at org.apache.jasper.compiler.Parser$Directive.accept(Parser.java:215)
	at org.apache.jasper.compiler.Parser.parse(Parser.java:1073)
	at org.apache.jasper.compiler.Parser.parse(Parser.java:1038)
	at org.apache.jasper.compiler.Parser.parse(Parser.java:1034)
	at org.apache.jasper.compiler.Compiler.compile(Compiler.java:182)
	at org.apache.jasper.runtime.JspServlet.loadJSP(JspServlet.java:413)
	at
org.apache.jasper.runtime.JspServlet$JspServletWrapper.loadIfNecessary(JspSe
rvlet.java:149)
	at
org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(JspServlet.ja
va:161)
	at org.apache.jasper.runtime.JspServlet.serviceJspFile(JspServlet.java:261)
	at org.apache.jasper.runtime.JspServlet.service(JspServlet.java:369)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:503)
	at org.apache.tomcat.core.ContextManager.service(ContextManager.java:559)
	at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC
onnectionHandler.java:160)
	at
org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.java:338
)
	at java.lang.Thread.run(Thread.java:484)

====================================================



-----Original Message-----
From: Craig R. McClanahan [mailto:Craig.McClanahan@eng.sun.com]
Sent: Friday, December 01, 2000 5:53 PM
To: taglibs-user@jakarta.apache.org; mbustany@lavastorm.com
Subject: Re: Q: Can I pass an array of type String to a tag lib


Mohammed Bustany wrote:

> Or does it only accept String?
>
> If it does accept an array, does it need any special conversion
> inside the set method?
>
> Please respond directly to my email address
> since I'm not subscribed to the mailing list.
>
> Thank you
>
> Mohammed
> LavaStorm, Inc.
>

You should be able to pass any Java object that is type-compatible with your
property setter method, if you use a runtime expression.  See below.

>
> ==================== EXAMPLE  ========================
>
> public class options
> {
>     private String selectedoption;
>     private String[] optionsList;
>
>     public void setOptionsList(String[] list)
>     {
>         optionsList = list;
>     }
>
>     ........ body of the tag here .......
>
> }
>
> ------- jsp file:
>
> <%! String[] list = { "January", "February", "March" }; %>
>
> <lava:listit  selectedoption="1" optionsList="list">
> .....
> .....
> </lava>

Try this instead:

    <lava:listit selectedoption="1" optionsList="<%= list %>" />

Be sure you declare that the optionsList attribute is allowed to accept
runtime
expressions in your tag library descriptor.

Craig McClanahan


Re: Q: Can I pass an array of type String to a tag lib

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

> Or does it only accept String?
>
> If it does accept an array, does it need any special conversion
> inside the set method?
>
> Please respond directly to my email address
> since I'm not subscribed to the mailing list.
>
> Thank you
>
> Mohammed
> LavaStorm, Inc.
>

You should be able to pass any Java object that is type-compatible with your
property setter method, if you use a runtime expression.  See below.

>
> ==================== EXAMPLE  ========================
>
> public class options
> {
>     private String selectedoption;
>     private String[] optionsList;
>
>     public void setOptionsList(String[] list)
>     {
>         optionsList = list;
>     }
>
>     ........ body of the tag here .......
>
> }
>
> ------- jsp file:
>
> <%! String[] list = { "January", "February", "March" }; %>
>
> <lava:listit  selectedoption="1" optionsList="list">
> .....
> .....
> </lava>

Try this instead:

    <lava:listit selectedoption="1" optionsList="<%= list %>" />

Be sure you declare that the optionsList attribute is allowed to accept runtime
expressions in your tag library descriptor.

Craig McClanahan