• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using JSTL with oddly structured data  RSS feed

 
Björn Chr Sebak
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im working on a stock trading application, and one of the things we need to render in our JSPs is whats called order depth for a financial instrument. Each order depth have x number of levels, which means that an order depth is basically a list of order depth levels. Each level have some attributes, like the asking and bidding price, name of seller and name of buyer. The logical step is to just have a List<OrderDepthLevel> where OrderDepthLevel is just a simple javabean with the attributes (ask, bid, buyer,seller) per level, which in turn is dead easy to render in a jsp foreach loop.

Problem is that when we get the order depth data from the data server, its given to the web server as a flat Map<String,String>. That means that all the order depth levels are packed in there with an appended integer id seperating the different levels. Youll find stuff like "ASK1", "BID5", "BUYER4" etc. This map is wrapped in a bean called OrderDepth, which have getters for ask, bid, seller and buyer, with an integer argument for the level you want, like getAsk(3) returns map.get("ASK"+i) etc. To avoid having to convert the map to a List<OrderDepthItems> (which means creatng lots of syntetical beans everytime some user wants to see the web page), why cant we just return the Map wrapper class itself to the view and let JSTL loop and extract each level. Well, it turns out that JSTL dont let us call getters with arguments.

I would like to create a simple loop with an integer going from 1..numOfLevels and call each getter with the int for each level in th jsp. Is this possible without resorting to scriptlets? is there some proven extension to JSTL that allows this?

 
Ramkumar Subburaj
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am unabel to understand the requirement completely.

Let me first explain my understanding.

There are different levels and under each level, you have a list contains list of orderDetails for that particular depth.

If this is the case, instead of using



you can use,



where the key(Integer) is the depth level and the value(List<OrderDetailsBean>) would be a list of orderdetails in the form of bean.

In this way, you can iterate over the Map in JSLT easily
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!