Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jstl question

 
Suman Sharma
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you tired so far? Where are you running into problems?
 
Suman Sharma
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I used these two lines. It is not clear to me.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..).
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In other words, you shouldn't simply be "converting" pages, you should be re-factoring.
 
Suman Sharma
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the answer. Thank you all of you for your help.

Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic