• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Bean not working with JSP

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
     
    Marshal
    Posts: 28193
    95
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The setter for mgrid triggers the populateCollection() method which fills the ArrayList.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic