7 Replies Latest reply on Nov 8, 2003 7:42 AM by jonlee

    Tag library -deploying the petsore1.1.2 reference applicatio

    venko

      Here is the problem.
      I am deploying the petsore1.1.2 reference application on jboss3.0.4
      The deployment is smooth after I made the required changes.
      When I click the category link (say Fish or Dog. Etc)
      It calls productcategory.jsp page.
      This page uses a JSP tag j2ee as
      <%@ taglib uri="/WEB-INF/tlds/taglib.tld" prefix="j2ee" %>
      <h3>This is a test text given in productcategory.jsp........</h3>
      <j2ee:productList numItems="4" category='<%=request.getParameter("category_id")%>'>

      If I remove the j2ee:productList tag it is working properly.
      But if I put the tag j2ee,the page is not coming. No errors or exceptions on the console.
      I tried following tricks
      Made a jar with all the classes for tag library and put the jar in /WEB-INF/lib
      In web.xml
      I added following lines

      <taglib-uri>/WEB-INF/tlds/taglib.tld</taglib-uri>
      <taglib-location>/WEB-INF/taglib.tld</taglib-location>

      Put the taglib.tld in WEB-INF and a copy of it in WEB-INF/tlds/taglib.tld

      I ensured in the target war file the required files and jars are available.
      Noting has worked.
      Any clue what is going wrong.
      Obviously the tag library classes is not found by class loader.But why and where is the problem??

        • 1. Re: Tag library -deploying the petsore1.1.2 reference applic
          martin0

          Hi venko,

          I appear to have hit the same problem (JBoss 3.0.8, petstore 1.1.2).
          InsertTag:doEndTag caught: org.apache.jasper.compiler.CompileException: /productcategory.jsp(12,0) Unable to find setter method for attribute: numItems

          Have you found a solution yet?

          Thanks
          Martin

          • 2. Re: Tag library -deploying the petsore1.1.2 reference applic
            jonlee

            I think Jasper cannot handle the nested <%=request.getParameter("category_id")%>. You may have better luck posing this question in the Apache Tomcat mailing-list I believe. But based on some past investigations with similar type constructs, I think that is the problem.

            • 3. Re: Tag library -deploying the petsore1.1.2 reference applic
              martin0

              Hi Jon,

              I've tried replacing the dynamic category specifier with an static value.

              It now reads
              <j2ee:productList numItems="4" category="FISH">

              but I get the same error :-(

              Thanks for the tip though - I'll keep looking.
              Have nice day in Australia!

              Martin

              • 4. Re: Tag library -deploying the petsore1.1.2 reference applic
                jonlee

                Did you sanity check the TLD? It has the getter and setter for the attribute and it doesn't have multiple copies with different parameter signatures? Just a thought so you rule out that issue.

                • 5. Re: Tag library -deploying the petsore1.1.2 reference applic
                  martin0

                  Hi Jon,

                  The tag element for productList looks like this:

                  productList
                  com.sun.j2ee.blueprints.petstore.taglib.list.ProductListTag
                  JSP

                  A tag that implements a my list, fetching a list from the
                  ProfileMgrWebImpl bean using the given number of items and starting
                  index. Should appear only in pages in which the ProfileMgrWebImpl bean
                  is being used.


                  <!-- no default -->

                  numItems
                  true
                  true


                  <!-- default is 1 -->

                  startIndex
                  false
                  true



                  category
                  true
                  true



                  Previously, I've tried referencing a non existant class in the tld, and I correctly get an error telling me that class can't be found:

                  InsertTag:doEndTag caught: org.apache.jasper.compiler.CompileException: /productcategory.jsp(13,0) Unable to load class com.sun.j2ee.blueprints.petstore.taglib.list.ProductListTag2

                  I'm using eclipse as the IDE & I note that it thinks the setNumItems(String) has a default scope (ie scope is package). The outline icon for setNumItems has a littlel green triangle by it. However the declaration looks correct (public). I think this is suspious!!!
                  Here is the whole file:

                  /** $Id: ProductListTag.java,v 1.9.4.2 2001/03/15 00:40:10 brydon Exp $
                  * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
                  * Copyright 2001 Sun Microsystems, Inc. Tous droits r?erv?.
                  */

                  package com.sun.j2ee.blueprints.petstore.taglib.list;

                  import java.lang.Exception;
                  import java.util.Collection;
                  import java.util.Locale;
                  import com.sun.j2ee.blueprints.shoppingcart.catalog.model.ListChunk;
                  import com.sun.j2ee.blueprints.petstore.control.web.CatalogWebImpl;
                  import com.sun.j2ee.blueprints.petstore.util.WebKeys;
                  import com.sun.j2ee.blueprints.petstore.util.JSPUtil;

                  /*
                  * ProductListTag
                  * ---------
                  * Extends the list tag. Fetches a list of products for the specified cateogry.
                  * Should be used in conjunction with ProductAttributeTags.
                  */
                  public class ProductListTag extends ListTag {

                  private String category = null;
                  private boolean hasNext = false;

                  protected void initParamPrefix() {
                  paramPrefix = "productList_" + category + "_";
                  }

                  protected Collection findCollection() throws Exception {
                  CatalogWebImpl catalog =
                  (CatalogWebImpl) pageContext.getServletContext().getAttribute(WebKeys.CatalogModelKey);
                  if (catalog == null) {
                  return null;
                  }
                  Locale locale = JSPUtil.getLocale(pageContext.getSession());
                  ListChunk prodList = null;
                  Collection products = null;
                  prodList = catalog.getProducts(this.category, startIndex-1, numItems, locale);
                  products = prodList.getCollection();
                  if ((startIndex -1 + products.size()) < prodList.getTotalCount()) hasNext = true;
                  else hasNext = false;
                  return(products);
                  }

                  protected boolean needsNextForm() {
                  return hasNext;
                  }

                  public void setCategory(String category) {
                  this.category = category;
                  }

                  // setters (overloaded to fix bug in tomcat)
                  public void setNumItems(String numItemsStr) {
                  super.setNumItems(numItemsStr);
                  }

                  public void setStartIndex(String startIndexStr) {
                  super.setNumItems(startIndexStr);
                  }
                  }


                  Also I don't understand how InsertTag (where the expection gets thrown) and ProductListTag are linked.

                  I'm appreciating your help.

                  Martin



                  • 6. Re: Tag library -deploying the petsore1.1.2 reference applic
                    martin0

                    Just noticed the info for ProductListTag says
                    A tag that implements a my list, fetching a list from the
                    ProfileMgrWebImpl bean using the given number of items and starting
                    index. Should appear only in pages in which the ProfileMgrWebImpl bean
                    is being used.

                    I can't see ProfileMgrWebImpl in the parent jsp page

                    I've tried including productcategory.jsp in this post, but I then get an error posting my reply so here's an attachment hopefully.

                    Thanks again
                    Martin

                    • 7. Re: Tag library -deploying the petsore1.1.2 reference applic
                      jonlee

                      The forums seem to be getting a bit unstable from this end in terms of access so hopefully this will get posted. I would look for an JSP or servlet example with this class being used. I'm not really that familiar with Petstore code, but I'm guessing that the Impl class will need to be imported in the JSP you intend to use it in and you will need to declare the bean. Use the example JSP you find as a guide to how the bean is used and the code required to declare and use it.