• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Scriptless page.

 
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Author
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic