logo       

twice the number of rows i expected: msg#00064

java.enhydra.xmlc

Subject: twice the number of rows i expected


i'm populating a table. my template has two rows in it. the two rows have different background colors. my code clones the first row over and over again, but sets the bg color of every other row to that of the second row in the template. there are 10 rows of data, but i get 20 rows in the output. when i move the "remove(altRow)" line up to after the "altRow.getBgColor()" line, the problem goes away.

is this a bug? code appended.

-- mike


HTMLTableRowElement row = indexPage.getElementForecastRow();
HTMLTableRowElement altRow = indexPage.getElementAlternateForecastR\ow();

String color1 = row.getBgColor();
String color2 = altRow.getBgColor();

// for each day in the forecast Iterator iter = forecast.iterator();
for (int i = 0; iter.hasNext(); i++) {

WeatherForecast day = (WeatherForecast) iter.next();

row.setBgColor((i % 2 == 0) ? color1 : color2);

indexPage.setTextDate(day.mDate.toString());
indexPage.setTextForecast1(day.mForecastText);
cloneRow(row);
}

remove(altRow);
remove(row);

// helper methods:

public static void cloneRow(HTMLTableRowElement pRow) {
pRow.getParentNode().insertBefore(pRow.cloneNode(true), pRow);
}

public static void remove(Node pNode) {
pNode.getParentNode().removeChild(pNode);
}


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise