wood burning stoves 2.0*
The moose likes JSP and the fly likes JSTL, Tomcat and ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL, Tomcat and ArrayList" Watch "JSTL, Tomcat and ArrayList" New topic
Author

JSTL, Tomcat and ArrayList

Graham Bunt
Greenhorn

Joined: Mar 23, 2012
Posts: 2
Hi,

First post to this site and think it is really useful etc. Hoping nobody will think - not this question again.

Using MySQL, Tomcat 6.0.12 and Java 5 on Windows Xp.

I'm putting together my own site with product catalogue, shopping cart etc. Not got to EJB etc. yet! I have factory classes for data/business layer to populate and return Product, Order and OrderLine objects etc. I decided it would be nice and clean to use JSTL and JSP for the presentation layer etc.

The problem is this:

My Order factory (java object) takes a cart object from my Checkout.jsp page and persists it in database (using bean) and returns a populated Order object. Fine so far:




Checkout.jsp Page

If I do this I get all the OrderLine objects on the server output in log as a test etc.



If I do this I get nothing.


If I do this, guess what, it works.


It just has me baffled, I know I'm missing something. The JSTL lib is in there and works in other pages for other Objects such as Product.
.

Any ideas or suggestions would be appreciated as I've narrowed down all the obvious errors such as checking getters an setters etc., know that it should work.

Just hope the answer is not too embarrassing.

Graham
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

Graham Bunt wrote:


Returning an ArrayList is rather an anti-pattern. Return a List instead -- who cares what the list implementation is? And if someone does care, it's wrong.

If I do this I get nothing.


Are you really getting nothing? Or are you just looking at the screen? Are you getting anything back in the HTML source? The unrenderred JSTL tags perhaps?

It just has me baffled, I know I'm missing something. The JSTL lib is in there and works in other pages for other Objects such as Product.

Put something really simple on the page to verify that the JSTL is fine and dandy on the page, and check the HTML source.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Graham Bunt wrote:If I do this I get nothing.

Shouldn't that be ${row.orderLineID}?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Graham Bunt
Greenhorn

Joined: Mar 23, 2012
Posts: 2
Many thanks for the useful comments. Alas ${row.getOrderLineID}} shoudl have read ${row.orderLineID} as you correctly pointed out. This was one of my last ditched attempts to get it to work but didn't reverse it out. EL statements must omit get or set but the methods need to be in the class and use camel case etc. Should have known better.

Uncommented the code below to see if they would output in the JSTL code in the Checkout.jsp page.



I also modified the embedded java code to confirm that the Collection contained my test OrderLine objects as well as the ones added via the OrderFactory object.

The Tomcat log confirms that at the Checkout.jsp page, that the OrderFactory has returned an Order object with a list of OrderLine objects. It has also added the test OrderLine objects above.

org.me.HelloWeb.OrderLine@9ac0f5
org.me.HelloWeb.OrderLine@1f21c50
org.me.HelloWeb.OrderLine@20f237
org.me.HelloWeb.OrderLine@fe315d
org.me.HelloWeb.OrderLine@5aebd9
org.me.HelloWeb.OrderLine@132021a

Now what is interesting or fustrating is that the forEach JSTL code outputs the OrderLine objects created in the Order object method, but nothing to be seen of the ones created in the OrderFactory object. Despite knowing that they are there in the Collection.



I will update the code to use List pattern throughout my code (thanks for that) and create a separate OrderFactory class that returns an Order object complete with an OrderLine Collection omitting the database element, just in case there is a data type to object translation problem.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSTL, Tomcat and ArrayList