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

Simple property not found?
Reusing JSP custom tags inside html
JSP Quiz process is not giving me the correct percentage scored
Refer the id variable of logic - iterate using jstl-el
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

Categories

HOME
vim
asp.net-core
relative-path
onedrive
lodash
sqlite-net-extensions
elm
twitter-bootstrap-4
survey
google-project-tango
alpha
yum
azure-media-services
indesign
primary-key
session-variables
fancybox-3
quicklook
collectd
php-7.1
gz
openrefine
pc
http-status-code-504
openedx
zapier
tokenize
language-agnostic
vlsi
selectedindexchanged
fabric8
semantic-versioning
contact-form
catel
catalog
http-digest
disassembling
scaffold
opshub
graphenedb
nand2tetris
eigenvalue
heightmap
total-commander
sencha-touch-2.3
thin
babel-core
cubic-spline
magma
nodebb
windows-iot-core-10
firmata
static-ip-address
slicknav
mikroc
mongocsharpdriver
plottable.js
jwplayer7
moveit
dlna
historian
separator
maven-tomcat-plugin
lemon
endeca-workbench
tmuxinator
quicklisp
service-accounts
apache-commons-fileupload
mmc
p2
rake-task
id3v2
google-reader
industrial
uv-mapping
bulkloader
eventlistener
dice
first-responder
wse3.0
buildr
deobfuscation
subgurim-maps
datareader
suppress
nhibernate.search
putchar
scripting-languages
django-notification
wsdl.exe
windows-live-messenger
uiq3

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