aspose file tools*
The moose likes JSP and the fly likes jstl question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "jstl question" Watch "jstl question" New topic
Author

jstl question

Suman Sharma
Ranch Hand

Joined: May 16, 2005
Posts: 72
Hello,
I am new to jstl. Can anyone tell me how to convert the following code to jstl code. Thank you.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

What have you tired so far? Where are you running into problems?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Suman Sharma
Ranch Hand

Joined: May 16, 2005
Posts: 72
Hello,
I used these two lines. It is not clear to me.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

Originally posted by Suman Sharma:

This action creates a scoped variable named vect (in page scope) from the scoped variable allrows that is in session scope. Is that what you want?

<cut value="vect.size()" />

This action emits the string "vect.size()" to the response. Probably not at all what you want. Besides, you can't call general methods with the EL. To get the length of a scoped variable, youd use the fn:length() JSTL function.

Before proceeding any further I'd heartily recommend that you grab a copy of the EL and JSTL specifications and give them a good reading.
[ March 18, 2008: Message edited by: Bear Bibeault ]
Suman Sharma
Ranch Hand

Joined: May 16, 2005
Posts: 72
Could you please tell me about a jstl resource that is to understand. I have to quickly convert jsp pages to jstl pages at my work.
Thank you.
Suman Sharma
Ranch Hand

Joined: May 16, 2005
Posts: 72
Hello,

I used following code. The java bean is in the warr package and the vector containg beans is in the session scope. It can't iterate in the for each loop. Can anyone help me with this problem.



javax.servlet.ServletException: Don't know how to iterate over supplied "items" in <forEach>

Thank you.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

<c:forEach var="warr.Rbean" items="${vecItem}" >

Why does var contain a class name? It should be the name of the scoped variable that will be created to contain each iteration instance. In this case, each element of ${vecItem}.

Whatever name you use, is the name you will reference within the loop.

If you do not have the JSTL Specification open on your desk in front of you, that is your next step.
[ March 20, 2008: Message edited by: Bear Bibeault ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Suman Sharma:
... I have to quickly convert jsp pages to jstl pages at my work.


JSTL/EL, by design, can't do everything that can be done with scriptlets.
This means that JSP applications written under a Model1 architecture may not be easy to 'convert' JSTL. Scriptless JSPs (pages built with only JSTL and EL) are designed to be used at the end of a Model, View, Controller processing chain. It is assumed that all the heavy lifting will be done by servlets, and Java objects before context is ever passed to the JSP which handles only marking up the results (HTML,CSS,Javasript,etc..).


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

In other words, you shouldn't simply be "converting" pages, you should be re-factoring.
Suman Sharma
Ranch Hand

Joined: May 16, 2005
Posts: 72
Hello,
I don't know what re-factoring means. I am trying to print out properties of each java bean objects that are stored in a vector. It is not able to iterate over items in the for loop. I have gone through books. I can't find the solution. Can you please give me some hint that would help me solve this code. Thank you.

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18674
    
    8

Refactoring: http://en.wikipedia.org/wiki/Refactoring

As for your question, what is the type of the object that JSTL can't iterate over? Now look at your JSTL documentation and read about how it iterates over collections.
Suman Sharma
Ranch Hand

Joined: May 16, 2005
Posts: 72
I found the answer. Thank you all of you for your help.

Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jstl question