Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scriptless page.

 
Shivani Chandna
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose I am creating a new Map

Now if we talk of scritpless jsp how would we be replacing the above script code? To avoid using scriptlets that is.

Another thing is : If i want to do

How would I go about doing that using EL?

This is giving an error.

Without using scripting - is there any other way to set values in variables/attributes ( Of course c:set is one of the using jstl lib - but is there any other way?)

Thanks,
Shivani
 
Ram Gokul
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you said for setting , we would use <c:set>

But for getting ,we can use the implicit pageScope Map. of EL
which means I would be using

"My movies / any lists are
${pageScope.MovieList.1},${pageScope.MovieList.2}" etc .
[ July 30, 2006: Message edited by: Ram Gokul ]
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now if we talk of scritpless jsp how would we be replacing the above script code? To avoid using scriptlets that is.
In short... you can't very easily. As far as I know, there are no standard tags for populating a map (and aside from <jsp:useBean>, which should be avoided here, there's no way to create a new HashMap instance either). This is mainly because the Map isn't a JavaBean. You can only use <c:set /> to replace the very last line of your example, where you set the page-scoped attribute called "movieMap".

You could populate the map if you created a new custom tag to do this for you (or found an existing custom tag somewhere else); in this case you might have:

<my:mapUpdate var="${ movieMap }" key="${ mykey }" value="${ myvalue }" />

which would work okay I suppose. However, if you're doing this sort of data population, you'd be much better putting the code in a servlet which then forwards to the JSP. It can store the map in the request scope. Accessing the map in the JSP is then very easy (see JSTL's <c:forEach> for example). The main lesson here is that JSPs should only present data they're provided with, they shouldn't obtain or modify it themselves.
How would I go about doing that using EL?
Very easy, just:would work consistently (since this is page-scope and is always searched first). Alternatively, the long-hand way:
This is giving an error.
That would be because EL is not like Java in many respects (it has some of the same operators, but that's about it). You can't invoke methods in EL - only a few (static) functions which must be predefined in the TLD. The expression language can only be used to retrieve values of variables, not set them.
 
MInu
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ram Gokul:
As you said for setting , we would use <c:set>

But for getting ,we can use the implicit pageScope Map. of EL
which means I would be using

"My movies / any lists are
${pageScope.MovieList.1},${pageScope.MovieList.2}" etc .

[ July 30, 2006: Message edited by: Ram Gokul ]





c:set tag wil not allow you to create a map object.
 
Ram Gokul
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I talked about setting an attribute .
Is it still not possible ?

<c:set var="myattribute" value="<% something.Map %>" >
</c:set>
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ram,


"My movies / any lists are
${pageScope.MovieList.1},${pageScope.MovieList.2}" etc .


In the above the EL like ${pageScope.MovieList.1} is illegal, as the value 1 is not valid java identifier, so you can not use the . operator.

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic