0

I am trying to load order data from different table.

I have displayed data also from tables using JOIN query.

This Is my o/p : enter image description here

I want something like this :

enter image description here

The Order ID i.e. No. here should be displayed once, if it repeats.

My JSP Code :

<table class="table table-condensed">
                        <%
                            List<String> oIdList = (List<String>)request.getAttribute("oIdList");
                            List<String> pNameList = (List<String>)request.getAttribute("pNameList");
                            List<String> pQtyList = (List<String>)request.getAttribute("pQtyList");
                            List<String> pTimeList = (List<String>)request.getAttribute("pTimeList");
                            List<Boolean> pStatusList = (List<Boolean>)request.getAttribute("statusList");
                        %>
                              <thead>
                                  <tr>
                                      <th width="8%">No.</th>
                                      <th width="23%">Product Name</th>
                                      <th width="20%">Product Qty</th>
                                      <th width="18%">Order Time</th>
                                      <th width="22%"><div align="center">Order Status</div></th>                                          
                                  </tr>
                              </thead>   
                              <tbody>

                              <%
                                    for(int i = 0; i<pNameList.size(); i++)
                                    {
                                        %>
                                            <tr>
                                                <td><%= oIdList.get(i) %></td>
                                                <td class="center"><%= pNameList.get(i) %></td>
                                                <td class="center"><%= pQtyList.get(i) %></td>
                                                <td class="center"><%= pTimeList.get(i) %></td>                                             
                                                <%
                                                    if(pStatusList.get(i))
                                                    {

                                                        %>                                                  
                                                            <td class="center"><div align="center"><span class="label label-success">Delivered</span></div></td>
                                                        <% 

                                                    }
                                                    else
                                                    {
                                                        %>
                                                            <td style="text-align: center;" width="9%"><span class="label">Pending</span></td>
                                                        <% 

                                                    }
                                                %>

                                            </tr>   
                                        <%
                                    }
                              %>


                              </tbody>
                         </table>

So Any Suggestion Please..

3 Answers3

1

Hello. buddy. try this

 for(int j =0,i = 0; i<pNameList.size(); i++) {
     %> <tr> <% 
    if(i==0){      
    j++;    
       %> <td><%= j %></td> <%
    }else if(oIdList.get(i) != oIdList.get(i-1)){
    j++;

         %> <td><%= j %></td> <%
    }else{
         %> <td></td> <%

    }    
   %>                                      

  <td class="center"><%= pNameList.get(i) %></td>
  <td class="center"><%= pQtyList.get(i) %></td>
  <td class="center"><%= pTimeList.get(i) %></td>  
Karthikeyan Sukkoor
  • 968
  • 2
  • 6
  • 24
0

Set a variable lastIdDisplayed to the id each time around the loop (initialize it to -1 or something else invalid). If lastIdDisplayed == id then don't display id.

Tim B
  • 40,716
  • 16
  • 83
  • 128
0

Your example is not very object-oriented. You should convert all these lists of string arrays into Order objects.

Then iterate over the Orders (sort them first by using a Comparable interface and comparing on the order id value).

Then use some basic logic to check if the last order id value is the same as the last.

Oliver Watkins
  • 12,575
  • 33
  • 119
  • 225