• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Bean not working with JSP

Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, maybe I'm oversharing, but I want to be thorough. Note I asked this question a different way using very different code.

Here's my jsp file - myq.jsp

Here's displayCollection.tag used by that jsp:

Here's the java class IrCollection (used as a bean in the tag):

and here's the InquireRecord java class used by IrCollection:

The JSP does this: set the mgr variable, which is passes to the tag, the tag then creates an instance of IrCollection using that mgr variable. (Yes, putting that populateCollection() method call in the setMgrid() method is probably Bad Practice, but it works, usually). The IrCollection objects builds an ArrayList of InquireCollection objects from an Access database. It then sets it's size property based on how many InquireCollection instances it put into the ArrayList. Once that's all done, the tag spits out 2 things: The size property and the mgrid property.

When I view the JSP, it gives me 0 for the size and Chris Novish for the mgrid.

I think this could be one of the following:
  • Not finding any matching records of the database
  • Not actually executing the populateCollection() method
  • some how forgetting the information it put into that ArrayList?

  • I"m sure there's another possibility, but I don't know.

    Here's what gets me. Here's a test class I made called TestCollection:

    if I run that I get a size of 4 and a mgrid of Chris Novish.

    Same data in, and it works as expected.

    So... why won't JSP do it?
    Posts: 25803
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You set the mgrid, then you do some JDBC stuff, then you set the size. So if you see mgrid being set but you don't see size being set, my guess is that some exception is thrown and then ignored between the two steps. Check wherever System.out is diverted to and look for stack traces there.
    Ranch Hand
    Posts: 144
    Oracle Fedora Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Your code never gets to perform the database execution. Here is what is happening in your code.

    You call the tag file with mgr attribute value set as "Chris Novish"
    Inside the tag file, the useBean tag creates a session scope bean with default values (zero length array, size = 0, and mgrid = null)
    The setProperty tag sets the value of the bean to mgrid to "Chris Novish"
    Immediately after, you print the size and mgrid properties which value the values 0 and "Chris Novish"

    Also, there is no reason to save the length of the array as an instance variables, just has getSize return the length of the iRecords array.

    Another big no-no, you should not have public instance variables. You should always follow the rules of encapsulation.
    Charessa Reilly
    Ranch Hand
    Posts: 39
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    The setter for mgrid triggers the populateCollection() method which fills the ArrayList.
    Without deviation from the norm, progress is not possible - Zappa. Tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
      Bookmark Topic Watch Topic
    • New Topic