• 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

JSTL, Tomcat and ArrayList

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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


Shouldn't that be ${row.orderLineID}?
 
Graham Bunt
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


reply
    Bookmark Topic Watch Topic
  • New Topic