This is a little bit complicated to elaborate and the title might be misleading but I don't know how to write it short.
I'm trying to display in a .jsp some images distributed 2 by 2. Example:
To do that, I have a 'while' loop, that for reasons of design, has to go 2 by 2. Like this: To do this I have an ArrayList of that are my DTOs, where I encapsulate my info (image, title, author).
The problem comes when I have an ArrayList with 3 or 5 elements. If I have only 1 element, it's easy to detect and display only one.
This is my code:
<%ArrayList<Vinilo> coleccionVinilos = (ArrayList<Vinilo>)request.getAttribute("coleccionVinilos");
request.removeAttribute("coleccionVinilos");
if(coleccionVinilos.size()>=2){
int i=0;
while( i < 6 && coleccionVinilos.size() > i) {
if(coleccionVinilos.size() > i){
Vinilo col = coleccionVinilos.get(4);
}
else{
Vinilo col = coleccionVinilos.get(i);
Vinilo col2 = coleccionVinilos.get(i+1);
}i=i+2; }
}
else if (coleccionVinilos.size()==1){
Vinilo col = coleccionVinilos.get(0);
}
else{}
%>
Aucun commentaire:
Enregistrer un commentaire