JMesa 3 tag library and Limit object

195 views
Skip to first unread message

quarkalone

unread,
Sep 14, 2010, 6:56:17 AM9/14/10
to JMesa
Hello,

I'm new to JMesa 3 and I'm trying to use the tag library with a very
long list of objects, so I'm trying to paginate from database.

In the previous version I obtain the Limit object with
TableFacadeFactory.createTableFacade, but this method is deprecated
now.

How can I get the limit object in the controller so I can search the
database for only the records I need?


Thanks.

Jeff Johnston

unread,
Sep 14, 2010, 10:55:45 AM9/14/10
to jm...@googlegroups.com

This should be much easier for you now.


What you need to do is call the TableModelUtils.getItems() method and implement the PageItems interface. What is nice about this is that you only need to worry about getting the total rows and items and do not have to do any other checks based on the order JMesa needs things.


Collection<?> items = TableModelUtils.getItems(id, request, new PageItems() {
    public int getTotalRows(Limit limit) {
    }

    public Collection<?> getItems(Limit limit) {
    }
});


You also do not have to worry about setting the Limit on the tags. Using this utils will set the Limit in the request by id and the tags will pick it up. This will work with the jmesa:tableFacade tag so you only have to move to the jmesa:tableModel tag when you have time.


Let me know if you have any problems...and also how things work out for you!


-Jeff Johnston







--
You received this message because you are subscribed to the Google Groups "JMesa" group.
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.


Luis Castro

unread,
Sep 16, 2010, 12:19:48 AM9/16/10
to jm...@googlegroups.com
Thanks for your timely answer. 

The database pagination works like a charm and indeed I think the new solution is better than the old one.

I'm sorry to say I'm having a little trouble with the  stateAttr="restore" attribute of tableModel tag.  Altought I've tried, I can't return to a filtered table by adding the attribute  "restore=true" to the url with the JMesa table.

In this week I will try again.  Does someone of you with more experience  have an advice to share in  this respect?
|
Thanks a lot.

Jeff Johnston

unread,
Sep 16, 2010, 1:16:10 AM9/16/10
to jm...@googlegroups.com
Yep. That looks like a bug. I can pretty clearly see what it is too.

I can get this fixed...would you mind testing it when I get this done? If you can then send me an email at jeff.johnston.mn@gmail.com and then I can send a jar out to you.

-Jeff

Nikhila Reddy

unread,
Jun 24, 2014, 1:46:21 PM6/24/14
to jm...@googlegroups.com
Hi,

I am trying the export feature of JMesa 3.0.4 with Struts2
Please find below my code

Struts.xml

         <action name="jmesaAction" class="com.sherwin.omps.opm.action.JmesaAction">
          <result>/jsp/opm/productEnquiry/prodEnqSearchResults2.jsp
          </result>
          </action>

Action class

public class JmesaAction extends BaseMpsAction{
   
    private String id;
    private ArrayList<ProductEnquiryDTO> enquiryList;
      
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public ArrayList<ProductEnquiryDTO> getEnquiryList() {
        return (ArrayList<ProductEnquiryDTO>) enquiryList;
    }
    public void setEnquiryList(List<ProductEnquiryDTO> enquiryList) {
        this.enquiryList = (ArrayList<ProductEnquiryDTO>) enquiryList;
    }

    public String execute(HttpServletRequest request, HttpServletResponse response){
       
        if (validateSession() != null) {
            return ERROR;
        }
        ArrayList<ProductEnquiryDTO> enquiryList = (ArrayList<ProductEnquiryDTO>) getDwrSession().getAttribute(ENQUIRY_LIST);
        TableModel tableModel = new TableModel("enquiryTbl",request,response);
        tableModel.setItems(enquiryList);

        tableModel.setExportTypes(ExportType.CSV, ExportType.EXCEL, ExportType.PDF);
        Table table = new Table().caption("Product Inquiry");

        Row row = new Row();
        table.setRow(row);

        Column pid = new Column("pcPidPk").title("PID");
        row.addColumn(pid);

        Column salesNumber = new Column("pcSkuUk").title("Sales Number");
        row.addColumn(salesNumber);

        Column status = new Column("statusItemsGtc05Code").title("Status");
        row.addColumn(status);

        Column productNumber = new Column("pcProductNbr").title("Product Number");
        row.addColumn(productNumber);
 
       
        if (tableModel.isExporting()) {
            tableModel.setTable(table);
            tableModel.render();
        }
        String view= tableModel.render();
        request.setAttribute("exportList",view);
        return SUCCESS;
       
    }
}
   

jsp file:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://displaytag.sf.net" prefix="display"%>
<%@ taglib prefix="jmesa" uri="/WEB-INF/tld/jmesa.tld"  %>
<link rel="stylesheet" type="text/css"
    href="<s:url value='/stylesheet/jmesa.css'/>" />
<script type="text/javascript" src="<s:url value='/scripts/jmesa/jquery.jmesa.js' />"></script>
<script type="text/javascript" src="<s:url value='/scripts/jmesa/jmesa.js' />"></script>
<script type="text/javascript"
    src="<s:url value='/scripts/opm.js' />"></script>
<script type="text/javascript"
    src="<s:url value='/scripts/omps.js' />"></script>
   
<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/jmesa/
jmesa.js">
</script>

<script type="text/javascript">
function onInvokeAction(id) {
    setExportToLimit(id, '');
    createHiddenInputFieldsForLimitAndSubmit(id);
}
</script>

<script type="text/javascript">
function onInvokeExportAction(id) {
    var parameterString = createParameterStringForLimit(id);
    location.href = '${pageContext.request.contextPath}/jmesaAction?' + parameterString;
  
   
}
</script>

<!-- using jmesa instead of display tag -->


<form action="prodEnquiry-search.action" method="post" id="prodEnqResultsForm" name="prodEnqResultsForm">
<input type="hidden" id="id" name="id" />
<input type="hidden" id="actionType" name="actionType" />
<s:actionmessage/>
<s:actionerror/>


    <jmesa:tableModel id="enquiryTbl" items="${enquiryList}" var="bean" exportTypes="pdf,csv,excel"
    maxRows="50" maxRowsIncrements="25,50,100" stateAttr="restore">
        <jmesa:htmlTable width="100%">
          <s:set var="pidValue" value="#attr.bean.pcPidPk"/>
            <jmesa:htmlRow uniqueProperty="pcPidPk" highlighter="true">
                <jmesa:htmlColumn property="pcPidPk" title="PID&nbsp;" >${pidValue}</jmesa:htmlColumn>
                <jmesa:htmlColumn property="pcSkuUk" title="Sales Number&nbsp;" filterable="false"/>
                <jmesa:htmlColumn property="statusItemsGtc05Code" title="Status&nbsp;" />
                <jmesa:htmlColumn property="pcProductNbr" title="Product Number&nbsp;" filterable="false" />
                <jmesa:htmlColumn property="pcUpcCodeUk" title="UPC Code&nbsp;" filterable="false"/>
                <jmesa:htmlColumn property="pcmfgCodeFk" title="Mfg Number&nbsp;" />
                <jmesa:htmlColumn property="pcMfgPartNumber" title="Mfg Part Number&nbsp;" filterable="false" />
                <jmesa:htmlColumn property="prodDesc" title="Product Description&nbsp;"/>
                 <jmesa:htmlColumn title="Action&nbsp;" filterable="false">
                <select id="actionType${pidValue}" onchange="javascript:forwardActionType(${pidValue},this.options[this.selectedIndex].value,'ProdInquiry')">
                <option value="S">Action</option>   
                <option value="View">View</option>   
                </select>
                </jmesa:htmlColumn>
            </jmesa:htmlRow>
        </jmesa:htmlTable>
    </jmesa:tableModel>
</form>


Can you please explain me what is wrong in my code?Its not at all going to my action class.
There is a firebug error saying jQuery not defined in jQuery.jmesa.js line 1001
Please help!

Regards,
Nikhila
Reply all
Reply to author
Forward
0 new messages