Dynamic number of columns using JSP Tag

685 views
Skip to first unread message

Kiran Krishnamurthy

unread,
Jun 10, 2012, 1:24:49 PM6/10/12
to jm...@googlegroups.com
Hi All,

I am new to JMESA and I want to put use the jmesa jsp tag for generating dynamic number of columns for one of my report generation requirements. here the number of columns will be dynamic as it will depend on the query being executed. i was able to do the same in displaytag till now.

  <display:table name="results" class="displayTag" sort="list" export="true" pagesize="20" requestURI="queryReportResult.action">  
    <% for (int i=0; i < displayProperties.length; i++) { %>
     <display:column property="<%=displayProperties[i].getName()%>" title="<%=displayProperties[i].getDisplayName()%>" sortable="true" headerClass="sortable" />
    <% } %>


i have tried 

<jmesa:tableModel id="tag" items="${listResults}" exportTypes="csv,excel,pdf" stateAttr="restore" var="bean">
        <jmesa:htmlTable  width="1000px">               
            <jmesa:htmlRow filterable="true">     
<c:forEach var="col" items="${listResults}">

                <jmesa:htmlColumn property="${col.name}"  sortable="true" filterable="true" filterEditor="org.jmesa.view.html.editor.DroplistFilterEditor"/>
</c:forEach> 
           </jmesa:htmlRow>
        </jmesa:htmlTable> 
    </jmesa:tableModel>

this is not working. pls suggest how to go abt this.

i also tried with generating the Table from the API

private String getHtmlTable(TableModel tableModel,
DisplayProperty[] display, String caption) {

HtmlTable table = new HtmlTable();
table.setWidth("80%");
table.caption(caption);
HtmlRow row = new HtmlRow();
table.setRow(row);
row.setFilterable(true);
row.setSortable(true);
for (int i = 0; i < display.length; i++) {
HtmlColumn col = new HtmlColumn(display[i].getName().replace(" ",
"_"));
col.setFilterable(true);
col.setSortable(true);
col.setFilterEditor(new org.jmesa.view.html.editor.DroplistFilterEditor());
row.addColumn(col);
}

tableModel.setTable(table);

return tableModel.render();
}

this works in rendering the dynamic columns well. but the other functionality of the toolbar is not working viz: next page, last page, sorting, page size change etc.

i have debugged in the Chrome javascript console and everything seems fine with the JS. 

pls let me know how to fix this.

thanks
Kiran

Jeff Johnston

unread,
Jun 12, 2012, 4:39:09 PM6/12/12
to jm...@googlegroups.com
For dynamic columns using the tag library you would use the htmlColumns tag.

http://code.google.com/p/jmesa/wiki/HtmlColumnsGenerator

The documentation for that is a little old. You no longer use the factory. Just create the columns like you did with the API.


Is the table inside a form tag? Also, do you have the onInvokeAction() JavaScript on the page?

-Jeff Johnston




Kiran

--
You received this message because you are subscribed to the Google Groups "JMesa" group.
To view this discussion on the web visit https://groups.google.com/d/msg/jmesa/-/9FMUEJCvhPwJ.
To post to this group, send email to jm...@googlegroups.com.
To unsubscribe from this group, send email to jmesa+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jmesa?hl=en.

Message has been deleted

Kiran Krishnamurthy

unread,
Jun 13, 2012, 3:06:58 PM6/13/12
to jm...@googlegroups.com
thanks for the reply.

i am using a form only.

 <form name="exportForm" action="${pageContext.request.contextPath}/QueryReport.jsp">

${reportresults}

</form>


</div>
<script type="text/javascript">
function onInvokeAction(id, action) {
    setExportToLimit(id, '');
    createHiddenInputFieldsForLimitAndSubmit(id);
}
function onInvokeExportAction(id) {
                var parameterString = $.jmesa.createParameterStringForLimit(id);
                location.href = '${pageContext.request.contextPath}/queryReportExport.action?' + parameterString;
            }
</script>

the page renders properly with all the data. the Export options all work fine but the next page, previous page, sorting, filtering, page size dont work at all.

the following is the source of the rendered page. everything seems to be fine but it still doesnt work.

  <form name="exportForm" action="/openreportsv2/QueryReport.jsp">



<div class="jmesa" >
<table id="jmesareport"  border="0"  cellpadding="0"  cellspacing="0"  class="table"  width="80%" ><caption>FLW Job Aid Usage Report</caption>
<thead>
<tr class="toolbar" >
<td colspan="10" >
<table border="0"  cellpadding="0"  cellspacing="1" >
<tr>
<td><img src="/openreportsv2/images/table/firstPageDisabled.gif"  alt="First" /></td>
<td><img src="/openreportsv2/images/table/prevPageDisabled.gif"  alt="Prev" /></td>
<td><a href="javascript:jQuery.jmesa.setPageToLimit('jmesareport','2');onInvokeAction('jmesareport','next_page')"><img src="/openreportsv2/images/table/nextPage.gif"  title="Next Page"  alt="Next" /></a></td>
<td><a href="javascript:jQuery.jmesa.setPageToLimit('jmesareport','4');onInvokeAction('jmesareport','last_page')"><img src="/openreportsv2/images/table/lastPage.gif"  title="Last Page"  alt="Last" /></a></td>
<td><img src="/openreportsv2/images/table/separator.gif"  alt="Separator" /></td>
<td><select name="maxRows"  onchange="jQuery.jmesa.setMaxRowsToLimit('jmesareport', this.options[this.selectedIndex].value);onInvokeAction('jmesareport','max_rows')" >
<option value="15"  selected="selected">15 </option><option value="50" >50 </option><option value="100" >100 </option>
</select></td>
<td><img src="/openreportsv2/images/table/separator.gif"  alt="Separator" /></td>
<td><a href="javascript:jQuery.jmesa.setExportToLimit('jmesareport','csv');onInvokeExportAction('jmesareport','export')"><img src="/openreportsv2/images/table/csv.gif"  title="CSV Export"  alt="csv" /></a></td>
<td><a href="javascript:jQuery.jmesa.setExportToLimit('jmesareport','jexcel');onInvokeExportAction('jmesareport','export')"><img src="/openreportsv2/images/table/excel.gif"  title="XLS Export"  alt="jexcel" /></a></td>
<td><a href="javascript:jQuery.jmesa.setExportToLimit('jmesareport','pdfp');onInvokeExportAction('jmesareport','export')"><img src="/openreportsv2/images/table/pdf.gif"  title="PDF Export"  alt="pdfp" /></a></td>
<td><img src="/openreportsv2/images/table/separator.gif"  alt="Separator" /></td>
<td><a href="javascript:onInvokeAction('jmesareport','filter')"><img src="/openreportsv2/images/table/filter.gif"  title="Filter"  alt="Filter" /></a></td>
<td><a href="javascript:jQuery.jmesa.removeAllFiltersFromLimit('jmesareport');onInvokeAction('jmesareport','clear')"><img src="/openreportsv2/images/table/clear.gif"  title="Clear"  alt="Clear" /></a></td>
</tr>
</table>
</td>
</tr>
<tr class="filter" >
<td><div class="dynFilter"  onclick="jQuery.jmesa.createDroplistDynFilter(this,'jmesareport','msisdn',{'11':'11','1116':'1116','1184':'1184','1219':'1219','1287':'1287','1306':'1306','1358':'1358','1371':'1371','1423':'1423','1463':'1463','153':'153','155':'155','190':'190','191':'191','211':'211','212':'212','2128':'2128','2159':'2159','2203':'2203','2263':'2263','2351':'2351','239':'239','2456':'2456','252':'252','258':'258','259':'259','262':'262','265':'265','268':'268','285':'285','298':'298','3119':'3119','3131':'3131','315':'315','3216':'3216','3307':'3307','3322':'3322','3333':'3333','34':'34','383':'383','421':'421','4303':'4303','47':'47','489':'489','493':'493','51':'51','5197':'5197','52':'52','5232':'5232','5336':'5336','6237':'6237','6279':'6279','6308':'6308','6435':'6435','6472':'6472','6494':'6494','7198':'7198','92':'92','96':'96'})" ></div></td>
<td><div class="dynFilter"  onclick="jQuery.jmesa.createDroplistDynFilter(this,'jmesareport','operator',{'airtel':'airtel','undefined':'undefined'})" ></div></td>
<td><div class="dynFilter"  onclick="jQuery.jmesa.createDroplistDynFilter(this,'jmesareport','name',{})" ></div></td>
<td><div class="dynFilter"  onclick="jQuery.jmesa.createDroplistDynFilter(this,'jmesareport','location_id',{'1':'1'})" ></div></td>
<td><div class="dynFilter"  onclick="jQuery.jmesa.createDroplistDynFilter(this,'jmesareport','time_id',{'128':'128'})" ></div></td>
<td><div class="dynFilter"  onclick="jQuery.jmesa.createDroplistDynFilter(this,'jmesareport','status',{'UNREGISTERED':'UNREGISTERED'})" ></div></td>
<td><div class="dynFilter"  onclick="jQuery.jmesa.createDroplistDynFilter(this,'jmesareport','type',{'CALL':'CALL'})" ></div></td>
<td><div class="dynFilter"  onclick="jQuery.jmesa.createDroplistDynFilter(this,'jmesareport','call_count',{'1':'1'})" ></div></td>
<td><div class="dynFilter"  onclick="jQuery.jmesa.createDroplistDynFilter(this,'jmesareport','secs_of_usage',{'356':'356'})" ></div></td>
<td><div class="dynFilter"  onclick="jQuery.jmesa.createDroplistDynFilter(this,'jmesareport','id',{'15009':'15009','15013':'15013','16061':'16061','16062':'16062','16064':'16064','16071':'16071','16080':'16080','16084':'16084','16086':'16086','16091':'16091','16094':'16094','16116':'16116','16122':'16122','16125':'16125','16126':'16126','16130':'16130','16133':'16133','16137':'16137','16149':'16149','16163':'16163','16164':'16164','16167':'16167','16170':'16170','16176':'16176','16183':'16183','16205':'16205','16209':'16209','16221':'16221','16248':'16248','16252':'16252','16257':'16257','16279':'16279','16282':'16282','16294':'16294','16297':'16297','16300':'16300','16307':'16307','16321':'16321','16324':'16324','16350':'16350','16360':'16360','16365':'16365','16367':'16367','16387':'16387','16395':'16395','16400':'16400','16403':'16403','16450':'16450','16458':'16458','16463':'16463','16474':'16474','16486':'16486','16498':'16498','16539':'16539','16540':'16540','16544':'16544','16545':'16545','16552':'16552','16560':'16560'})" ></div></td>
</tr>
<tr class="header" >
<td><div onmouseover="this.style.cursor='pointer'"  onmouseout="this.style.cursor='default'"  onclick="jQuery.jmesa.addSortToLimit('jmesareport','0','msisdn','asc');onInvokeAction('jmesareport', 'sort')" >Msisdn</div></td>
<td><div onmouseover="this.style.cursor='pointer'"  onmouseout="this.style.cursor='default'"  onclick="jQuery.jmesa.addSortToLimit('jmesareport','1','operator','asc');onInvokeAction('jmesareport', 'sort')" >Operator</div></td>
<td><div onmouseover="this.style.cursor='pointer'"  onmouseout="this.style.cursor='default'"  onclick="jQuery.jmesa.addSortToLimit('jmesareport','2','name','asc');onInvokeAction('jmesareport', 'sort')" >Name</div></td>
<td><div onmouseover="this.style.cursor='pointer'"  onmouseout="this.style.cursor='default'"  onclick="jQuery.jmesa.addSortToLimit('jmesareport','3','location_id','asc');onInvokeAction('jmesareport', 'sort')" >Location _id</div></td>
<td><div onmouseover="this.style.cursor='pointer'"  onmouseout="this.style.cursor='default'"  onclick="jQuery.jmesa.addSortToLimit('jmesareport','4','time_id','asc');onInvokeAction('jmesareport', 'sort')" >Time _id</div></td>
<td><div onmouseover="this.style.cursor='pointer'"  onmouseout="this.style.cursor='default'"  onclick="jQuery.jmesa.addSortToLimit('jmesareport','5','status','asc');onInvokeAction('jmesareport', 'sort')" >Status</div></td>
<td><div onmouseover="this.style.cursor='pointer'"  onmouseout="this.style.cursor='default'"  onclick="jQuery.jmesa.addSortToLimit('jmesareport','6','type','asc');onInvokeAction('jmesareport', 'sort')" >Type</div></td>
<td><div onmouseover="this.style.cursor='pointer'"  onmouseout="this.style.cursor='default'"  onclick="jQuery.jmesa.addSortToLimit('jmesareport','7','call_count','asc');onInvokeAction('jmesareport', 'sort')" >Call _count</div></td>
<td><div onmouseover="this.style.cursor='pointer'"  onmouseout="this.style.cursor='default'"  onclick="jQuery.jmesa.addSortToLimit('jmesareport','8','secs_of_usage','asc');onInvokeAction('jmesareport', 'sort')" >Secs _of _usage</div></td>
<td><div onmouseover="this.style.cursor='pointer'"  onmouseout="this.style.cursor='default'"  onclick="jQuery.jmesa.addSortToLimit('jmesareport','9','id','asc');onInvokeAction('jmesareport', 'sort')" >Id</div></td>
</tr>
</thead>
<tbody class="tbody" >
<tr id="jmesareport_row1"  class="odd"  onmouseover="this.className='highlight'"  onmouseout="this.className='odd'" >
<td>92</td>
<td>undefined</td>
<td>&#160;</td>
<td>1</td>
<td>128</td>
<td>UNREGISTERED</td>
<td>CALL</td>
<td>1</td>
<td>356</td>
<td>15009</td>
</tr>
<tr id="jmesareport_row2"  class="even"  onmouseover="this.className='highlight'"  onmouseout="this.className='even'" >
<td>96</td>
<td>undefined</td>
<td>&#160;</td>
<td>1</td>
<td>128</td>
<td>UNREGISTERED</td>
<td>CALL</td>
<td>1</td>
<td>356</td>
<td>15013</td>
</tr>
</tbody>
<tbody>
<tr class="statusBar" >
<td align="left"  colspan="10" >Results 1 - 15 of 59.</td>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript" >
jQuery(document).ready(function(){
jQuery.jmesa.addTableFacade('jmesareport');
jQuery.jmesa.setMaxRowsToLimit('jmesareport','15');
jQuery.jmesa.setTotalRowsToLimit('jmesareport','59');
jQuery.jmesa.setPageToLimit('jmesareport','1');
jQuery.jmesa.setOnInvokeAction('jmesareport','onInvokeAction');
jQuery.jmesa.setOnInvokeExportAction('jmesareport','onInvokeExportAction');
jQuery.jmesa.setContextPath('jmesareport','\/openreportsv2');
});
</script>



</form>





</div>

<script type="text/javascript">

function onInvokeAction(id, action) {

    setExportToLimit(id, '');

    createHiddenInputFieldsForLimitAndSubmit(id);

}

function onInvokeExportAction(id) {

                var parameterString = $.jmesa.createParameterStringForLimit(id);

                location.href = '/openreportsv2/queryReportExport.action?' + parameterString;

            }

</script>









Jeff Johnston

unread,
Jun 13, 2012, 3:26:53 PM6/13/12
to jm...@googlegroups.com
Did you include the jmesa.js file as well? You would be using it with the createHiddenInputFieldsForLimitAndSubmit call, although I would expect JavaScript errors.

Can you try it in Firefox and see if you see anything different? JMesa works across all browsers but for testing it might clue us into what is going on.

-Jeff



--
You received this message because you are subscribed to the Google Groups "JMesa" group.
To view this discussion on the web visit https://groups.google.com/d/msg/jmesa/-/VJQ9K-ISzW8J.

Kiran Krishnamurthy

unread,
Jun 14, 2012, 1:24:39 AM6/14/12
to jm...@googlegroups.com
Yes.. i have included the jmesa.js as well. The javascript is getting called.. i can see the URL's query string params changing everytime i click the options but the same is not reflecting in the page rendering.

pls find attached the full view source of the page that is rendered.

thanks
Kiran
To unsubscribe from this group, send email to jmesa+unsubscribe@googlegroups.com.
test.html
Reply all
Reply to author
Forward
0 new messages