This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
Hi there I have a small application (Java and JSP) that, amongst other things, displays a client's portfolio details - funds, stocks and cash, using WML as the markup language. A client can have multiple portfolios. I am currently using hashtables to display the portfolio names, then the total value of the portfolio, then break the portfolio value down into separate totals for funds, stocks and cash. I am having trouble with my second hashtable, which displays the total portfolio value. For a given portfolio id, there can be only one record in the database. The portfolio id is the primary key. The results of the SQL SELECT statement (which works correctly as a straight database query) are placed into a ResultSet by a bean called PortfolioBean. The short form of this name in the code pasted below is simply 'portfolio'. The contents of the ResultSet are then placed into a hashtable called portfolio_breakdown_hashtable. The JSP page calls a get method on a holding class called PortfolioBreakdown, which contains methods returning the elements of the hashtable. When I run the JSP, the value returned for any of the amounts (stocks, funds or cash) is 0.0 If I call the method getPortfolioName, nothing at all appears on the screen (note: 'null' is NOT displayed). I am pretty confident that the hashtable does have elements in it, as otherwise I would not get the card titled "display" appear on screen. I have a feeling that the problem is that I have to use the Hashtable method nextElement, when in fact there is only one element in the hashtable - or am I wrong? Maybe my understanding of what constitutes an element is wrong? Please could you have a look at my code and advise. Maybe there is another approach altogether that I should be using? If possible, however, I would like to continue using hashtables. Many thanks, Clive. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ < relevant portion of JSP page> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++==
Your problem is in your constructors. You are creating a bunch of local variables here, NOT assigning the values to your instance variables. When you later call this.variable you get your instance variable, which you initialized to 0F or "". Take off the floats and Strings in your constructor, and you no longer are creating local variables, but are instead using the instance variables. Hope that helps Jason [This message has been edited by jason adam (edited September 28, 2001).]
Chicken Farmer ()
Joined: May 08, 2001
Actually, what the code should look like is:
[This message has been edited by jason adam (edited September 28, 2001).]
Joined: Sep 28, 2001
Thanks Jason, this works fine - thanks also to Cindy and JavaRanch for a great site! Till next time, Clive.