File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Scriptless page. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Scriptless page." Watch "Scriptless page." New topic
Author

Scriptless page.

Shivani Chandna
Ranch Hand

Joined: Sep 18, 2004
Posts: 380
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


/** Code speaks louder than words */
Ram Gokul
Ranch Hand

Joined: Oct 07, 2005
Posts: 85
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

Joined: Mar 27, 2003
Posts: 836
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.


Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
MInu
Ranch Hand

Joined: Oct 09, 2003
Posts: 517
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.


God Gave Me Nothing I Wanted<br />He Gave Me Everything I Needed<br /> - Swami Vivekananda
Ram Gokul
Ranch Hand

Joined: Oct 07, 2005
Posts: 85
I talked about setting an attribute .
Is it still not possible ?

<c:set var="myattribute" value="<% something.Map %>" >
</c:set>
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
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


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Scriptless page.
 
Similar Threads
map is an ArrayList, compiler knows that Object is superclass of ArrayList, yet does nothing?
html link with params
Map....
Enthuware question doubt on EL
HashMap()