• Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp table

 
phani ravinutala
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a arraylist list = da.getdata(String str);


In the above if loop suppose if the condition is true for two times, I want to add up the two row's cnt and show the calculated amount on jsp page.

for example if the count is 5 and 7. I want to show only 12

Can anyone help me in this case?

thanks


 
Charbel Keyrouz
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are drawingt the td inside the loop while if I got you correctly it should be outside the loop
so replace this:

<% java.util.Iterator j = list.iterator();
StrMsgDO strDO;
int cnt =0;
while(j.hasnext()){
strDO = (StrMsgDO)j.next();
<%if(strDO.getDetail().equals("AOP")){%>
cnt +=strDO.getCount();
<td ><span class="Normal"> <%= cnt %></span></td>
<%}%>

with this:

<% java.util.Iterator j = list.iterator();
StrMsgDO strDO;
int cnt =0;
while(j.hasnext()){
strDO = (StrMsgDO)j.next();
if(strDO.getDetail().equals("AOP"))
{
cnt +=strDO.getCount();
}
}%>
<td ><span class="Normal"> <%= cnt %></span></td>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Charbel Keyrouz, please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.
 
phani ravinutala
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply. Suppose if I have more column to display other then cnt on jsp, then
I can't close the while loop for example



 
Charbel Keyrouz
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you leave the tds inside the loop then you will have the cnt value repeated in all rows.
In order to help you most please post to me the layout you are wishing to display and accordingly we can correct the loop.

I apologize for not putting my code in tags.
 
phani ravinutala
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Here is the below layout




In the above table I want to add up two rows 12 and 13 with same code 001 to 5+7 =12 and show only one row and one value 12 .

I hope you understand my question.

thanks
 
phani ravinutala
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Here is the below layout





I would like to add up the two rows with same id 001 ie 5+7 =12 . I want to show the single row like below



 
phani ravinutala
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Charbel Keyrouz , Please let me know, If you don't understand my problem.


thanks
 
Charbel Keyrouz
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for not answering earlier was a bit away.
Now I see your need exactly.

But I think the problem is from the source of data.
We can do this by code but it is not that good.

Can you please post me the query that you are using to get the data and we can start from there.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!