aspose file tools*
The moose likes Struts and the fly likes Querying DB and Iterating over the resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Querying DB and Iterating over the resultset" Watch "Querying DB and Iterating over the resultset" New topic
Author

Querying DB and Iterating over the resultset

RushiKumar Bhatt
Greenhorn

Joined: Mar 13, 2009
Posts: 2
Hi everyone

I am stumped at this:
I am querying my Database using HQL. This part of the process is working just fine, as when I debug, I can clearly see that the variable contains set of elements with the needed data. however, in my JSP page, when I iterate over the list, I get the funky Ljava.lang output:

[[Ljava.lang.Object;@1d5e499, some.path.action.Class@15f1ace, com.opensymphony.xwork2.DefaultTextProvider@d8f317]


Now, I understand that I need to have it output as a string, but how to do this with strut's iterator?
This is how I am iterating over the list, in my jsp page:



Here is what "myList" variable contains, once it executes the query:

myList
--elementData
----[0]
------[0]
-------- 1
------[1]
-------- This is the description
----[1]
------[0]
-------- 2
------[1]
-------- Second description


I cannot change the value from "[0]" or "[1]" to something else, as this is how they are stored in the list



Please shed some light on this
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Using a bare "[n]" OGNL expression evaluates to the stack minus the top n entries, which will almost never be what you want.

Set the var of the iterator and use that:I'm skeptical that that's what the HQL would return, though; an HQL query normally returns a collection of domain objects, from which you should be able to access properties by their proper names.
RushiKumar Bhatt
Greenhorn

Joined: Mar 13, 2009
Posts: 2
Hello Mr. Newton,

That worked!!

Thank you, Sir!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Querying DB and Iterating over the resultset
 
Similar Threads
nested iterator using List and Map in struts2
Struts iterator tag value attribute
How to access a property attribute of a value outside of an iterate, but within another iterate
How to iterate through List of objects using OGNL <s:iterator> tag in struts2