db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Veronique Couderc <veroniq...@sensorynet.co.uk>
Subject criteria?
Date Tue, 13 Jul 2004 11:00:56 GMT


 

Hi,

 I need to sort a column but the content is the result of a calculation:

DecimalFormat roundPercentage = new DecimalFormat("0");


part of code:
=============
	Criteria cr = new Criteria();

	cr.addJoin(ItemPeer.SYSTEMID, SystemPeer.SYSTEMID);
	cr.addJoin(ItemPeer.STAGEID, StagePeer.STAGEID);
	cr.addJoin(StagePeer.STAGETEMPLATEID, StageTemplatePeer.STAGETEMPLATEID);
	cr.addJoin(ItemPeer.ITEMTYPEID, ItemTypePeer.ITEMTYPEID);
	
	String TABLE_NAME = "stage";
		
	cr.addAlias("NEXTSTAGE", StagePeer.TABLE_NAME);
	cr.addAlias("NEXTSTAGETEMPLATE", StageTemplatePeer.TABLE_NAME);
	cr.addJoin(ItemPeer.NEXTSTAGEID, "NEXTSTAGE.STAGEID");
	cr.addJoin("NEXTSTAGE.STAGETEMPLATEID", "NEXTSTAGETEMPLATE.STAGETEMPLATEID");

	
{...}

TableHeadFormat th = new TableHeadFormat("tableheads", "wlink", urlPrefix, btnDown, btnUp,
isAsc, sortOrder);

{...}

<%= th.format(ItemTypePeer.DESCRIPTION, "Item Type") %>
    <%= th.format(SystemPeer.NAME, "System") %>
	<%= th.format(ItemPeer.JTD, "JTD") %>
	<%= th.format(ItemPeer.TAG, "Tag") %>
	<%= th.format(StageTemplatePeer.DESCRIPTION, "Status") %>
	<%= th.format("NEXTSTAGETEMPLATE.DESCRIPTION", "Next Stage") %>
	
	

    <th class=tableheads nowrap>% Complete</th>  // that column should be formated
as the ones above

{...}    


Iterator i = items.iterator();
while(i.hasNext()) {
	double pc;
		
    Item item = (Item) i.next();
	if(item.getNextStage().getStageId() == Stage.DONE) {
		pc = 100.0;
	}
	else {
		int done = item.getHistory().size();
		int total = item.getItemType().getStages().size();
		pc = 100.0 * done / total;
	}
%>

<tr>
<td class=columnwhite><%=item.getItemType().getDescription()%></td>
<td class=columnwhite><%=item.getSystem().getName()%></td>
<td class=columnwhite><%=item.getJtd()%></td>
<td class=columnwhite><%=item.getTag()%></td>
<td class=columnwhite><%=item.getStage().getStageTemplate().getDescription()%></td>
<td class=columnwhite><%=item.getNextStage().getStageTemplate().getDescription()%></td>
<td class=columnwhite><%=roundPercentage.format(pc)%>%</td>
    <td class=columnwhite width="75"> 
      <table width="100%" border="0" cellspacing="0" cellpadding="0" style="border:1px
solid #000000;">
        <tr>
		  <% if (pc > 0.00001) {%>
          <td width="<%=pc%>%"><img src="images/bargrph_blue.gif" width="100%"
height="10"></td>
		  <%}%>
		  <% if (pc < 100.00000) {%>
          <td bgcolor="#CCCCFF"><img src="images/bargrph_spacer.gif" width="1" height="10"></td>
		  <%}%>
        </tr>
      </table>
    </td>
</tr>
<%		
}


Iterator i = items.iterator();
Hashtable ht = new Hashtable();
while(i.hasNext()) {
	double pc;
		
    Item item = (Item) i.next();
	if(item.getNextStage().getStageId() == Stage.DONE) {
		pc = 100.0;
	}
	else {
		int done = item.getHistory().size();
		int total = item.getItemType().getStages().size();
		pc = 100.0 * done / total;
	}

    String html = "";
    html += "<td class=columnwhite>" +item.getItemType().getDescription()+  "</td>";
    html += "<td class=columnwhite>" +item.getSystem().getName()+  "</td>";
    html += "<td class=columnwhite>" +item.getJtd()+  "</td>";
    html += "<td class=columnwhite>" +item.getTag()+  "</td>";
    html += "<td class=columnwhite>" +item.getStage().getStageTemplate().getDescription()+
 "</td>";
    html += "<td class=columnwhite>" +item.getNextStage().getStageTemplate().getDescription()+
 "</td>";
    html += "<td class=columnwhite>" +roundPercentage.format(pc)+  "%</td>";
	html += "<td class=columnwhite width=75><table width=100% border=0 cellspacing=0
cellpadding=0 style=border:1px solid #000000;><tr>";
	if (pc > 0.00001) {
	html += "<td width=" +pc+ "><img src=images/bargrph_blue.gif width=100% height=10></td>";
	}
	if (pc < 100.00000) {
    html += "<td bgcolor=#CCCCFF><img src=images/bargrph_spacer.gif width=1 height=10></td>";
	}
    html += "</tr></table></td></tr>";

	ht.put(roundPercentage.format(pc), html);
}

SortedMap sortedMap = new TreeMap();
sortedMap.putAll(ht);

Iterator iter = sortedMap.keySet().iterator();
while (iter.hasNext()) {
	
    Object key = iter.next();
    out.println(key + "=" + sortedMap.get(key));
}

//Here I've added the way I found to sort that column the problem is that the table is sorted
in that order but not because of clicking on the header of the column as I want, hope my request
is clear!

is it possible to do that with criteria?

Thanks
vero


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message