jsp-tags


JSP foreach tag for two variables


I want to do something like this
<c:forEach var="item1" items="List1" var="item2" items="List2">
<p> ${item1} ${item2}</p>
</c:forEach>
One solution is to iterate through both the List, if both are of same size
<c:forEach var="i" begin="0" end="$(fn:length(List1))">
<p> <%= List1.get(i) %> <%= List2.get(i)%> //wrong syntax
</c:forEach>
Any idea how to achieve this.
You can call varStatus.index to get the index of the current round and then use it as a lookup for the second list. Mind the length of the Lists though or it will throw an Exception . Set the items with the List having maximum of the two.
<c:forEach var="element" items="${List1}" varStatus="status">
<p>
${element}
${List2[status.index]}
</c:forEach>
Documentation.
How to avoid Java Code in JSP-Files?
Array is Frist List, and B is Second List and varStatus.index to get the index of the current round and then use it as a lookup for the second list.
<c:forEach var="Array" items="${A}" varStatus="status">
<c:out value="${A}","${B[status.index]}"}/>
</c:forEach>

Related Links

Invalid tagdir attribute while web-fragment is used
JSP foreach tag for two variables
Adding Parameter to href tag before uri
Servlet exception stream closed jsp
creating and exporting a csv from Display tag table
bean write to number type id
restrict image file size in alloy UI
The function getContextPath must be used with a prefix when a default namespace is not specified
how can i retrive parameters from EncodeURL using jsp?
onclick tag giving error in h:commandLink
Displaytag - How to pass hidden value in url?
Embedding Tag Files in a JAR
Errors when the compiler is trying to build a custom JSP tag based on an Java Bean
Creating nested custom tag using jsp2 tag files
Unable to access session on JSP
Dealing with <html:options>

Categories

HOME
cakephp
keras
c#-4.0
drivers
dictionary
onedrive
fme
tesseract
mean-stack
youtube-dl
adb
jira
twitter-bootstrap-4
azure-storage-tables
multiple-records
contact
slurm
ssl-client-authentication
node-pdfkit
numeral.js
quickbooks
moonmail
static-libraries
hex-editors
flask-wtforms
carthage
caml
netflix
after-effects
google-static-maps
database-replication
beyondcompare
autoconf
cas
functor
contact-form
phpfreechat
language-concepts
wpf-controls
revolution-slider
jquery-bootgrid
xcode-extension
swisscomdev
multilingual
awt
sfdc
s
qwt
alphabet
knockout-components
imanage
chord-diagram
wdf
android-textview
radtreelist
probability-density
netmq
natvis
collapse
fouc
directoryservices
formatjs
website-monitoring
operator-precedence
ng-animate
camanjs
file-copying
uitouch
dml
phpthumb
jboss-weld
batterylevel
dataadapter
mylyn
plasma
comaddin
eventlistener
clipper
hosts-file
online-compilation
regsvr32
bubble-chart
gnustep
netbeans-7.1
icanhaz.js
preference
paul-graham

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App