File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Struts 2 Aggregated Lists and Select Boxes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2 Aggregated Lists and Select Boxes" Watch "Struts 2 Aggregated Lists and Select Boxes" New topic
Author

Struts 2 Aggregated Lists and Select Boxes

Eugene Williams
Greenhorn

Joined: Jan 31, 2010
Posts: 20
I have a JPA query which returns an aggregated list from a domain object. It looks something like this:
What this does is returns a list to my Action class that I can then iterate using the Struts 2 iterator tag like so:This works great for presenting lists with count relative displayed values, but when I try to display the list data in a select box, things don't work so well - meaning, I get nothing - I can't seem to access the indexed information. I've tried the following:
But the select box has no data.

Can anyone help steer me in the right direction? I'm trying to keep from having to either 1) write a separate procedure to generate this list or 2) have to build my own select list using a standard (more code to keep up with) approach:
Thanks
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Not sure why you're trying to access element 0 inside an iterator, but that's a different issue.

The OGNL expression will go against the top of the stack: just use "id" and "author".
Eugene Williams
Greenhorn

Joined: Jan 31, 2010
Posts: 20
Thanks for the reply David. I've tried your recommendation and it didn't work. This is how I modified my statement:

The reason I'm doing this is because I have one named query that's used to generate all lists of books; this query is used in a number of contexts throughout the application. In certain views displaying the list, I require that the total number of books returned in the query be known, so that in paging, I can make a statement such as "Displaying 50-75 of 340 Books". Having my query return an aggregated value from "count" representing the total number of books (rows) allows me to do this (unless there's another way). In most views, I can access the data using an OGNL expression that references the indexed position of the COUNT aggregate - the aggregate resided at and the actual "book" object for the current row during iteration residing at with all relevant information about the book stored in it. As stated earlier - this methodology works flawlessly in circumstances where I'm using the "s:iterator", but in those where I have to use the "s:select" tag to access the list, I can't seem to access the column of the "book" object.

Thanks again for the response.

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

It makes no sense to store the count in the list of books, besides that's it's already available as the size collection attribute.

Better to clean up the representation first, then approach the actual issue.
Eugene Williams
Greenhorn

Joined: Jan 31, 2010
Posts: 20
When paging the results, the size of the list is determined by the value specified in the DAO.

Please review my first post to get a better understanding of the objective.

Eugene Williams
Greenhorn

Joined: Jan 31, 2010
Posts: 20
To better clarify, in the DAO, I limit the size of the results returned by the query using the following:As you can see, the size of the list will only be 25 objects. The table contains many more. The view needs to know how many are actually in the table. This is why my SQL query includes the "count" column.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 2 Aggregated Lists and Select Boxes