• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

creating a map using JSTL

 
Niranjan PY Prasad
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks i want to create a map using only JSTL and want to set key and value to that map. and also want to retrive the values in that map.

I only want to use JSTL.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JSTL and EL are primarily intended to consume data rather than create it, so their ability to do so is quite limited.

For example, you cannot create a new object instance.

It's customary to create the data instances in the servlet controller prior to forwarding to the JSP.
[ March 20, 2007: Message edited by: Bear Bibeault ]
 
Niranjan PY Prasad
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Bear,

is there any way to create a map using <c:set /> ?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.
If you need to do this, you're probably not using JSTL properly.
 
Tim Cor
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Niranjan PY Prasad wrote:Hi folks i want to create a map using only JSTL and want to set key and value to that map. and also want to retrive the values in that map.

I only want to use JSTL.


 
Per Lindberg
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if you're not so strict about using only JSTL:

This example creates a Map specifying columns to hide (later).

It has the advantage that it can be included several times in the same JSP, since jspUseBean does not tolerate duplicate id:s.
(Another way might be to use a JSP tag file).

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mixing scriptlets into the JSP along with JSTL and EL is a big old mess. I would not recommend this.
 
Per Lindberg
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed. Hiding the the bean in e.g. tag context would be cleaner.
And, of course, if you only need one instance, then jsp:useBean is The Right Thing.
Any other neat alternatives?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd just create it in the page controller like anything else needed for the page.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic