• 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

Arraylist and Hashtable issue

 
Ranch Hand
Posts: 253
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers,

I am having an ArrayList with Hashtables. I iterated ArrayList on jsp. But iam not getting values in select box..please check my jsp, dao and dbutils.

MyJSP



MY DAO





Please check my code and tell me where iam doing mistake.

Thanks
Vipul Kumar.
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Before you look at JSP, make sure your result set has records then array list is not empty.

I suggest you may want to use the old fashion simpler way (aka looping the result set directly) inside your listUsers() method to make sure it's not the query. If that works, then it's your DBUtil.rsToArrayList() method.
 
vipul John
Ranch Hand
Posts: 253
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rancher,

Thanks for the reply. Data is coming from database. Please verify my jsp. tell me how to access hashmap value in a arraylist

Thanks
vipul kumar
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
requirement is you need to show the list of map key/value's right?

I am going to tell you how to display list of maps in jsp.

here you go: Use Servlet and JSP. just call the servlet first, then forward to jsp from there...

in servlet:


In JSP:(index.jsp)


simple! is not it?

* if you follow design1 architecture(using only JSPs) . then you need to move servlet logic to a class
and the class processing should take before the JSTL loop.

 
vipul John
Ranch Hand
Posts: 253
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rancher,

Thanks for response. which version of core tags allowing expressions in items attribute.?

Thanks
Vipul Kumar.
 
vipul John
Ranch Hand
Posts: 253
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rancher,


i am getting this exception .

Exception:- According to TLD or attribute directive in tag file, attribute items does not accept any expressions

that is why, i asked jstl core tags version

Thanks
Vipul Kumar.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vipul bondugula wrote:
Exception:- According to TLD or attribute directive in tag file, attribute items does not accept any expressions


do you use <%= %> ? perhaps, it is not supported in JSTL1.0
 
vipul John
Ranch Hand
Posts: 253
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rancher,


I am using EL Expressions.

Thanks
Vipul Kumar
 
Bartender
Posts: 1845
10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are using JSTL1.0. You should be using JSTL1.1 at least.

The issue is with your tag library declaration:

should be

(note the subtle addition of /jsp in there)

JSTL1.0 is intended for old containers - Servlet 2.3/JSP1.2. (eg Tomcat 4)
If you are using anything newer than that then use the JSTL1.1 uri.
JSP2.0 is the point at which EL expressions started being interpreted by the server, which was a fundamental change for the tag library - so they gave it a new URI to distinguish which to use.




 
vipul John
Ranch Hand
Posts: 253
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Stefan,


Expression Language issues solved. EL expressions are embedded in jsp 2.0. Thanks for the information.

But my issue is , start of the post. to display elements in hashmap which is in arraylist..

Thanks
Vipul Kumar.
 
Stefan Evans
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I thought Seetharaman had already answered your query, and my answer was to help with troubleshooting an error message with his solution.
Taking a closer look at his answer, it doesn't seem to be what you were implementing.

This should be closer:



Changes I made
- added EL expression markers to the "items" attribute on your c:forEach.
- changed your <c:forEach> loop to nest the <option> values within it.
- removed the useBean statements. They are not necessary when using EL and JSTL. Only when you are using scriptlets as they define a scriptlet variable on the page as well as putting the bean in scope.
- changed the syntax ${mapItem["user_id"] } to ${mapItem.user_id} which is equivalent.

That should do it.

Returning a List of Maps indexed by column name is a bit of a code smell because database columns might be renamed etc without you ever being informed about it, thus breaking the page.
Preferable would be to define a java bean to return the values to the page that you want, and load values from the result set into a List of Beans.

 
vipul John
Ranch Hand
Posts: 253
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Stefan

Returning a List of Maps indexed by column name is a bit of a code smell because database columns might be renamed etc without you ever being informed about it, thus breaking the page.
Preferable would be to define a java bean to return the values to the page that you want, and load values from the result set into a List of Beans.



Even though below question is irrelavent , please answer query....

Suppose if iam using struts 1.2. can i use form bean as a java bean to return values to the page...form bean is also a java bean , right?

Thanks
Vipul Kumar.
 
Stefan Evans
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using Struts1.2 you might have more luck in our Struts forum :-)

But yes, you can use the form bean to return values to the page. In fact I'm pretty sure that is a common use case.
Normally you should work within the bounds of the framework though rather than short-circuiting things.

However, with my previous answer returning a list of beans rather than a list of maps, my answer remains the same.
A List of beans is always preferable to a list of maps because it defines more strictly what the values are, and they won't change if you change your database columns.
The only difference with stripes is I might use the form to return that list rather than setting it as an scoped attribute.



 
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
Copied to the Struts forum.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic