[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

how to find size of the feeds at JSTL

Hello

I need to find the size of the JSTL and write it to end="size of the feed " at the following code. Could you please help me how to find the size of the feed?

Regards
Altaico

 <x:forEach begin="0" end="4" var="story"
                   select="$doc/rss/channel/item" varStatus="status">
//end = "size of the rss"
0
elaltaico
Asked:
elaltaico
  • 8
  • 4
1 Solution
 
rrzCommented:
Do you want to know item count ?
<x:forEach begin="0" end="4" var="story"
                   select="$doc/rss/channel/item" varStatus="status">
<c:set var="itemCount" value="${itemCount +1}" />
</x:forEach> 
Item count is <c:out value="${itemCount}" />

Open in new window

0
 
elaltaicoAuthor Commented:
Hello

i want to end rss at the end of the item count . it means it will begin from 0 and end at the last.(all the items). So how i can write itemcount without writing it inside <x:forEach begin="0" end="4">

Cheers
0
 
elaltaicoAuthor Commented:
or is there any specific method that i can find feed sizE?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
rrzCommented:
>So how i can write itemcount without writing it inside <x:forEach begin="0" end="4">  
If you want to find the number of items, then you can use XPath function in a JSTL <x:out>  tag.
<x:out select="count($doc//item)" />  
If that is not what you want, then please define
>feed sizE  
0
 
elaltaicoAuthor Commented:
       <x:forEach var="story" begin="0" end="<x:out select='count($doc/rss/channel/item)'/>"
                   select="$doc/rss/channel/item" > should work but it does not :((

Error is :java.lang.NumberFormatException: For input string: "<x:out select='count($doc/rss/channel/item)'/>"
      java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
0
 
rrzCommented:
I am sure what you are trying to do here.
Why do need to know the number of items in advance ?
If you just want to loop through the nodeset, then you don't have to use the begin and end attributes. Please try the following example code.
Number of items is <x:out select="count($doc//item)" /><br/>
<x:forEach select="$doc/rss/channel/item" > 
        <x:out select="title/text()" /><br/>
</x:forEach>

Open in new window

0
 
rrzCommented:
error
I am *not* sure what you are trying to do here.
0
 
elaltaicoAuthor Commented:
rrz@871311 I need to put 4 rss item at one page and next page will use same URL but differnet begin point and different end point.As a result of that I need to get size of rss and make a mathematical function to put 4 rss feed at one page and put the remaining rss feeds at last page. That'S why I need to get rss feed size at beginning. I hope I was clear. Apologizes if I was not clear at beginning. Thank you in advance.


Regards
0
 
rrzCommented:
Please try the following example code.
<x:set select="count($doc//item)" var="itemCount" />
<br/>First page:<br/>
<x:forEach var="story" begin="0" end="3" select="$doc/rss/channel/item" > 
                      <x:out select="title/text()" /><br/>
</x:forEach>
<br/>Second page:<br/>
<x:set select="count($doc//item)" var="itemCount" />
<x:forEach var="story" begin="4" end="${itemCount}" select="$doc/rss/channel/item" > 
                      <x:out select="title/text()" /><br/>
</x:forEach>

Open in new window

0
 
rrzCommented:
That last code will work for on a single page. If you want to display on separate pages, then add scope attribute.
<x:set select="count($doc//item)" var="itemCount" scope="session" />
Make doc session-scoped as well.
0
 
rrzCommented:
Error: no need to set itemCount twice.
Please try the following example code.
<x:set select="count($doc//item)" var="itemCount" scope="session"/>
<br/>First page:<br/>
<x:forEach var="story" begin="0" end="3" select="$doc/rss/channel/item" > 
                      <x:out select="title/text()" /><br/>
</x:forEach>
<br/>Second page:<br/>
<x:forEach var="story" begin="4" end="${itemCount}" select="$doc/rss/channel/item" > 
                      <x:out select="title/text()" /><br/>
</x:forEach>

Open in new window

0
 
rrzCommented:
Did that last code work for you ?
0
 
mrcoffee365Commented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now