java - Spring Mvc display data from multiple Lists in Jsp -
hi there using spring mvc , trying display data from multiple lists in jsp page. i've searched , found similar topics wasn't able achieve trying plus got more confused. model class contains this:
private string blabla1; private string blabla2; private list<string> alpha; private list<string> beta; ..... //getters setters
what want display table in jsp values these 2 lists (alpha , beta ..) one value @ column.they both have same number of values. example
<tr><td>alpha.value1</td><td>beta.value1</td></tr> <tr><td>alpha.value2</td><td>beta.value2</td></tr> ...................................... <tr><td>alpha.valuen</td><td>beta.valuen</td></tr>
as i've seen here rendering data in jsp using spring controllers , different classes
and other examples, create that: list<myobjects> objects
myobjects model has private string ... , not list<string>..
i tried construct
map<string,list<string>> test = new hashmap<string,list<string>>();
then
test.put("alfa", alpha); test.put("beta", beta);
but got display them in 2 rows , single column using
<c:foreach var="testvalue" items="${test}"> <tr><td>${testvalue.value}</td></tr> </c:foreach>
please don't aske me change model class, 'impossible'. i've seen somewhere saying use collection i'm not sure how that.
any suggestion useful, happy coding!
model.addobject("alphalist", alpha); model.addobject("betalist", beta);
in jsp :
<c:foreach var="listitem" items="${alphalist}" varstatus="thecount" > <tr><td>${listitem}</td><td>${betalist[thecount.index]}</td></tr> </c:foreach>
note :
${thecount.index}
starts 0${thecount.count}
starts 1.
so can use count iterate on second list.
Comments
Post a Comment