JSP: Create Dynamic 2 Column Table looping through iter.hasNext()

Hi,

I have created an ArrayList which I populate with 2 strings per element - if such a thing exists. for example my array would have

{ccc, email}

{bbb,ip}

{aaa,dsl}

{ddd,tv}

I then sort this list using Collections.sort in which case I end up with the following:

aaa, dsl

bbb, ip

ccc, email

ddd, tv

However, I want display the contents in 1 table with 2 columns with a check box in front of each

i.e.

checkbox - aaa, dsl checkbox ccc, email

checkbox- bbb, ipcheckbox ddd, tv

I would be happy if the table was like the above, however, even if if bbb,ip printed in the right column I would be ok.

This list example only contains 4 rows now but it could be 5 rows, 6 rows, 7 etc. It can grow/strink so that would be dynamic as well.

I think I need to build a for loop or while loop and to somehow spit out the contents of the first element then increment and check against total lsit and do the second td statement etc. But I am not totally sure. Anyhow, I hope I haven't confused anyone who reads this. Appreciate any help or direction. Thanks

[1152 byte] By [Flash99a] at [2007-11-26 15:45:17]
# 1

Question - is the two column requirement for the interface or is it inherent in your datastructure? The only reason you seem to have a list with two strings per element. is because you want to display it in two columns.

If that is the case, you are mixing up your view and model layers, and are going to have trouble further down the track.

If it is just a logical list of items, leave it as a simple list.

The jsp page should worry about how to render this straight list of elements as a two column table

evnafetsa at 2007-7-8 22:04:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

the reason each list element contains 2 pieces of data is so that I can keep the login and type together for sorting purposes and can probably display the login -aaa along with the correct type Email etc.

here is a snip of the code if it will help.

List listTmp = new ArrayList();

ArrayList allLogins = new ArrayList();

for(int i=0;i<service_output.length;i++)

{

String[] tmpStr = new String[2];

n = service_output.indexOf('(');

if (n > 0)

{

serviceType = service_output.substring(0, n);

restOfString = service_output.substring(n+1);

int atsign_index = 0;

atsign_index = restOfString.indexOf('@');

if ((atsign_index) > 0)

{

loginPrefix = restOfString.substring(0, atsign_index);

tmpStr[0] = loginPrefix;

tmpStr[1] = serviceType;

LoginServType login1 = new LoginServType (tmpStr[0], tmpStr[1]);

allLogins.add(login1);

serviceCount++;

}

else

{

continue;

}

}

else

{

continue;

}

}

roundServices= new BigDecimal(serviceCount/maxcols).setScale(2, BigDecimal.ROUND_UP);

Collections.sort(allLogins);

//Iterator iter = allLogins.iterator();

for (Iterator iter = allLogins.iterator(); iter.hasNext();)

{

LoginServType loginiter = (LoginServType)iter.next();

String tempService = myformat.translateService(loginiter.getServType());

%>

<table summary="" class="dataDisplay borderCollapse autoLayout width100pc">

<colgroup>

<col class="alignLeft width30pc" />

<col class="alignRight width30pc" />

</colgroup>

<thead>

<tr>

<th class="alignLeft sublabel_display"></th>

</tr>

</thead>

<tbody>

<tr class="">

<input type="checkbox" name="username" value="<%=loginiter.getLogin()%>"><%=loginiter.getLogin()%> -

<%=tempService%>

<%iter.next(); %>

<input type="checkbox" name="username" value="<%=loginiter.getLogin()%>"><%=loginiter.getLogin()%> -

<%=tempService%>

</tr>

</tbody>

</div>

<%

}//end of for loop

%>

</table>

</div>

</div>

Flash99a at 2007-7-8 22:04:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...