aspose file tools*
The moose likes JSP and the fly likes A quick JSTL ordering problem. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "A quick JSTL ordering problem." Watch "A quick JSTL ordering problem." New topic
Author

A quick JSTL ordering problem.

Paul Duer
Ranch Hand

Joined: Oct 10, 2002
Posts: 98
Hiya guys...

I am doing a little content managment piece in JSTL. I need to take 5 of the same type of object and sort them, all in JSTL on a JSP page.

My object has Rank, Title, Date, and Text as the properties. Each object will have a Rank between 1 and 100. I will load the objects in to a container object with setter/getters for each property.

Now I want to sort the objects by rank and then print them out.

Here's what I have so far but it prints nothing:

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61657
    
  67

You are doing a few odd things on your page, and are making a mis-assumption.

Firstly, you do not need to embed the <c:set>'s in the useBean tags. I don't think it will cause any problems, but it's a bit misleading.

Secondly, why are you mixing scriptlet expressions with JSTL as in:



Or, is the scriptlet expression just there for diagnostic purposes?

Lastly, you are assuming that the tag:



will add an entry into the map at scoped variable prMap. If you examine the size of the map before and after you will see that it remains at zero. The 'target' attribute is intended to set the properties of beans. It'd be nice if it could be used to add entries into maps, but that doesn't appear to be the case.

I can't be sure without looking at the JSTL source, but I imagine that the tag is looking for a bean mutator for the property identified by pr1_rank and failing when it doesn't find one.

Rather than trying to set up data structures in the JSP page itself, I'd step back and evaluate following the more common pattern of having a servlet controller set up the strutures needed for the page (where, in Java code, you have all the flexibility in the world) and then forward to the JSP in order to render the view.
[ November 05, 2004: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Duer
Ranch Hand

Joined: Oct 10, 2002
Posts: 98
Thanks Bear,

In this case I do not have the luxury of using servlets to control the pages. It sounds strange, but it's an out of the box Websphere Commerce site. So I can't really create new servlets.

I was able to change the code in the bottom section to meet my needs like this:



I would still like to distill it down. I wish I could programmatically go through my properties bundle, but that isn't an option or at least I don't know how to.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61657
    
  67

Ah, the old forced-to-program-in-a-straight-jacket problem. Been there.

At least I would entertain the idea of abstracting the processing off the page and into a bean where, once again, you have the full power of Java at your fingertips.

Not optimum, but better than doing on-page contortions.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A quick JSTL ordering problem.