I want to know how to store a value from data iterator in a JSF page, so that I can use it in multiple place in a single iteration. Lets, say I want to display a particular value in 5 different places in a screen.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m not sure about the problem you’re struggling with. It sounds much like as if you’re using JSF on JSP and are using scriptlets for that wherein you’re repeating the
Iterator#next()call multiple times within the loop body. This is indeed not going to work. Callingnext()will obviously return the next item. You basically need to get hold of it in a variable only once in the loop and then reuse that variable multiple times. But anyway, using scriptlets in a JSF page is a huge smell.When using JSP as view technology, the proper way would be using JSTL
<c:forEach>tag or any JSFUIDatacomponent, such as<h:dataTable>or Tomahawk’s<t:dataList>. All of them offers avarattribute wherein you can specify the scoped attribute name of the currently iterated item. You can use it as many times as you want in the tag body.E.g.
When you’re using Facelets as view technology (which -fortunately- doesn’t support scriptlets), you should be using the
<ui:repeat>tag for this.