is it possible to change get variable values from an JSTL array like on Java? [duplicate]
This question already has an answer here:
Loop through a Map with JSTL [duplicate]
2 answers
I want to know how to pass the code below to jstl changing the name according to index.
List<Map> inventariozonas = new ArrayList<Map>();
for(int i = 1; i < 20; i++){
Map r3 = new HashMap();
r3.put("puntoventa", "puntoventa"+i);
inventariozonas.add(r3);
}
I've been trying to get values in HTML by JSTL but I don't know how to get them dynamically due every variable has a different name.
With the code below just repeat the same value.
<c:forEach items="${inventariozonas}" var="r">
<tr>
<td>${r.puntoventa1}</td>
</tr>
</c:forEach>
Is there any possibility to do something like this:
<c:forEach items="${inventariozonas}" var="r">
<tr>
<td>${r.puntoventa+index}</td>
</tr>
</c:forEach>
javascript java jstl
marked as duplicate by Community♦ Jan 7 at 22:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Loop through a Map with JSTL [duplicate]
2 answers
I want to know how to pass the code below to jstl changing the name according to index.
List<Map> inventariozonas = new ArrayList<Map>();
for(int i = 1; i < 20; i++){
Map r3 = new HashMap();
r3.put("puntoventa", "puntoventa"+i);
inventariozonas.add(r3);
}
I've been trying to get values in HTML by JSTL but I don't know how to get them dynamically due every variable has a different name.
With the code below just repeat the same value.
<c:forEach items="${inventariozonas}" var="r">
<tr>
<td>${r.puntoventa1}</td>
</tr>
</c:forEach>
Is there any possibility to do something like this:
<c:forEach items="${inventariozonas}" var="r">
<tr>
<td>${r.puntoventa+index}</td>
</tr>
</c:forEach>
javascript java jstl
marked as duplicate by Community♦ Jan 7 at 22:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
the question here is, what is your purpose of all this? get all elements of each Map in the map or what exactly?
– YCF_L
Jan 1 at 11:07
add a comment |
This question already has an answer here:
Loop through a Map with JSTL [duplicate]
2 answers
I want to know how to pass the code below to jstl changing the name according to index.
List<Map> inventariozonas = new ArrayList<Map>();
for(int i = 1; i < 20; i++){
Map r3 = new HashMap();
r3.put("puntoventa", "puntoventa"+i);
inventariozonas.add(r3);
}
I've been trying to get values in HTML by JSTL but I don't know how to get them dynamically due every variable has a different name.
With the code below just repeat the same value.
<c:forEach items="${inventariozonas}" var="r">
<tr>
<td>${r.puntoventa1}</td>
</tr>
</c:forEach>
Is there any possibility to do something like this:
<c:forEach items="${inventariozonas}" var="r">
<tr>
<td>${r.puntoventa+index}</td>
</tr>
</c:forEach>
javascript java jstl
This question already has an answer here:
Loop through a Map with JSTL [duplicate]
2 answers
I want to know how to pass the code below to jstl changing the name according to index.
List<Map> inventariozonas = new ArrayList<Map>();
for(int i = 1; i < 20; i++){
Map r3 = new HashMap();
r3.put("puntoventa", "puntoventa"+i);
inventariozonas.add(r3);
}
I've been trying to get values in HTML by JSTL but I don't know how to get them dynamically due every variable has a different name.
With the code below just repeat the same value.
<c:forEach items="${inventariozonas}" var="r">
<tr>
<td>${r.puntoventa1}</td>
</tr>
</c:forEach>
Is there any possibility to do something like this:
<c:forEach items="${inventariozonas}" var="r">
<tr>
<td>${r.puntoventa+index}</td>
</tr>
</c:forEach>
This question already has an answer here:
Loop through a Map with JSTL [duplicate]
2 answers
javascript java jstl
javascript java jstl
edited Jan 1 at 10:56


azro
11.4k41639
11.4k41639
asked Jan 1 at 10:56
xiul2194xiul2194
111
111
marked as duplicate by Community♦ Jan 7 at 22:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Community♦ Jan 7 at 22:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
the question here is, what is your purpose of all this? get all elements of each Map in the map or what exactly?
– YCF_L
Jan 1 at 11:07
add a comment |
the question here is, what is your purpose of all this? get all elements of each Map in the map or what exactly?
– YCF_L
Jan 1 at 11:07
the question here is, what is your purpose of all this? get all elements of each Map in the map or what exactly?
– YCF_L
Jan 1 at 11:07
the question here is, what is your purpose of all this? get all elements of each Map in the map or what exactly?
– YCF_L
Jan 1 at 11:07
add a comment |
1 Answer
1
active
oldest
votes
You can try this way :
<c:forEach items="${inventariozonas}" var="r" varStatus="vs">
<tr>
<td>${r['puntoventa' + vs.index]}</td>
</tr>
</c:forEach>
- First to get the index you can use varStatus, for more details read this How to get a index value from foreach loop in jstl
- to get the value from a map you can use
r['key']
, for more details read this Get value from hashmap based on key to JSTL.
If you want to loop over the element of each map, then would suggest this way instead :
<c:forEach items="${inventariozonas}" var="myMap">
<c:forEach items="${myMap}" var="entry">
<tr>
<td>${entry.value}</td>
</tr>
</c:forEach>
</c:forEach>
1
Here ${vs.index}, ${} is not necessary cause vs.index is already inside a ${}.
– Md. Nasir Uddin Bhuiyan
Jan 1 at 11:10
thank you @Md.NasirUddinBhuiyan this is correct :)
– YCF_L
Jan 1 at 11:10
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can try this way :
<c:forEach items="${inventariozonas}" var="r" varStatus="vs">
<tr>
<td>${r['puntoventa' + vs.index]}</td>
</tr>
</c:forEach>
- First to get the index you can use varStatus, for more details read this How to get a index value from foreach loop in jstl
- to get the value from a map you can use
r['key']
, for more details read this Get value from hashmap based on key to JSTL.
If you want to loop over the element of each map, then would suggest this way instead :
<c:forEach items="${inventariozonas}" var="myMap">
<c:forEach items="${myMap}" var="entry">
<tr>
<td>${entry.value}</td>
</tr>
</c:forEach>
</c:forEach>
1
Here ${vs.index}, ${} is not necessary cause vs.index is already inside a ${}.
– Md. Nasir Uddin Bhuiyan
Jan 1 at 11:10
thank you @Md.NasirUddinBhuiyan this is correct :)
– YCF_L
Jan 1 at 11:10
add a comment |
You can try this way :
<c:forEach items="${inventariozonas}" var="r" varStatus="vs">
<tr>
<td>${r['puntoventa' + vs.index]}</td>
</tr>
</c:forEach>
- First to get the index you can use varStatus, for more details read this How to get a index value from foreach loop in jstl
- to get the value from a map you can use
r['key']
, for more details read this Get value from hashmap based on key to JSTL.
If you want to loop over the element of each map, then would suggest this way instead :
<c:forEach items="${inventariozonas}" var="myMap">
<c:forEach items="${myMap}" var="entry">
<tr>
<td>${entry.value}</td>
</tr>
</c:forEach>
</c:forEach>
1
Here ${vs.index}, ${} is not necessary cause vs.index is already inside a ${}.
– Md. Nasir Uddin Bhuiyan
Jan 1 at 11:10
thank you @Md.NasirUddinBhuiyan this is correct :)
– YCF_L
Jan 1 at 11:10
add a comment |
You can try this way :
<c:forEach items="${inventariozonas}" var="r" varStatus="vs">
<tr>
<td>${r['puntoventa' + vs.index]}</td>
</tr>
</c:forEach>
- First to get the index you can use varStatus, for more details read this How to get a index value from foreach loop in jstl
- to get the value from a map you can use
r['key']
, for more details read this Get value from hashmap based on key to JSTL.
If you want to loop over the element of each map, then would suggest this way instead :
<c:forEach items="${inventariozonas}" var="myMap">
<c:forEach items="${myMap}" var="entry">
<tr>
<td>${entry.value}</td>
</tr>
</c:forEach>
</c:forEach>
You can try this way :
<c:forEach items="${inventariozonas}" var="r" varStatus="vs">
<tr>
<td>${r['puntoventa' + vs.index]}</td>
</tr>
</c:forEach>
- First to get the index you can use varStatus, for more details read this How to get a index value from foreach loop in jstl
- to get the value from a map you can use
r['key']
, for more details read this Get value from hashmap based on key to JSTL.
If you want to loop over the element of each map, then would suggest this way instead :
<c:forEach items="${inventariozonas}" var="myMap">
<c:forEach items="${myMap}" var="entry">
<tr>
<td>${entry.value}</td>
</tr>
</c:forEach>
</c:forEach>
edited Jan 1 at 11:10
answered Jan 1 at 10:58


YCF_LYCF_L
33.2k104283
33.2k104283
1
Here ${vs.index}, ${} is not necessary cause vs.index is already inside a ${}.
– Md. Nasir Uddin Bhuiyan
Jan 1 at 11:10
thank you @Md.NasirUddinBhuiyan this is correct :)
– YCF_L
Jan 1 at 11:10
add a comment |
1
Here ${vs.index}, ${} is not necessary cause vs.index is already inside a ${}.
– Md. Nasir Uddin Bhuiyan
Jan 1 at 11:10
thank you @Md.NasirUddinBhuiyan this is correct :)
– YCF_L
Jan 1 at 11:10
1
1
Here ${vs.index}, ${} is not necessary cause vs.index is already inside a ${}.
– Md. Nasir Uddin Bhuiyan
Jan 1 at 11:10
Here ${vs.index}, ${} is not necessary cause vs.index is already inside a ${}.
– Md. Nasir Uddin Bhuiyan
Jan 1 at 11:10
thank you @Md.NasirUddinBhuiyan this is correct :)
– YCF_L
Jan 1 at 11:10
thank you @Md.NasirUddinBhuiyan this is correct :)
– YCF_L
Jan 1 at 11:10
add a comment |
the question here is, what is your purpose of all this? get all elements of each Map in the map or what exactly?
– YCF_L
Jan 1 at 11:07