Problem on RemoveRowWorksheetEditor

48 views
Skip to first unread message

ryLuis

unread,
May 7, 2012, 2:06:40 PM5/7/12
to jm...@googlegroups.com
hi Jeff and all jmesa user,

i tried to use RemoveRowWorksheetEditor to remove row from the table, but when i run my application, the image of 'removeWorksheetRow.png' is not shown to the table and the remove function is also not working (please view below image)

i am using jmesa-3.0.4,

here is the code of my jsp  :


<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="/WEB-INF/tld/jmesa.tld" prefix="jmesa"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>


</head>
<body>
<form name="contactListForm" action="${pageContext.request.contextPath}/contactListForm.html">
<!-- ${contacts} -->

<c:choose>
<c:when test="${isEmpty == 'true'}">
<h2>Contact Manager has no data !</h2>
</c:when>

<c:otherwise>
<jmesa:tableModel id="contactList" items="${contacts}" maxRows="8" exportTypes="csv,excel"
maxRowsIncrements="8,16,24" filterMatcherMap="com.learning.controller.tag.TagFilterMatcherMap" stateAttr="restore"
var="bean">
<jmesa:htmlTable captionKey="contacts.caption" width="600px">
<jmesa:htmlRow>
<jmesa:htmlColumn property="remove" title="&nbsp;" filterable=" false" sortable="true"
worksheetEditor="org.jmesa.worksheet.editor.RemoveRowWorksheetEditor" />
<jmesa:htmlColumn property="firstName" title="First Name" />
<jmesa:htmlColumn property="lastName" title="Last Name" />
<jmesa:htmlColumn property="email" />
<jmesa:htmlColumn property="telephone" />
</jmesa:htmlRow>
</jmesa:htmlTable>
</jmesa:tableModel>
</c:otherwise>
</c:choose>

</form>


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

</body>
</html>



Can you please advise what is the problem ?


regards.


Jeff Johnston

unread,
May 7, 2012, 2:15:40 PM5/7/12
to jm...@googlegroups.com
You should take a look at the worksheet tutorial. You need to set the tableModel to editable and add a row identifier.

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

-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/-/u1dP48TmY4QJ.
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.

ryLuis

unread,
May 8, 2012, 3:43:44 AM5/8/12
to jm...@googlegroups.com
Hi Jeff,

yes i missed that step, really appreciate for your correction.

regards.

ryLuis

unread,
May 8, 2012, 5:47:52 AM5/8/12
to jm...@googlegroups.com
hi Jeff,

i have implements the delete function successfully, but when i click the 'save changes' button, the tables is not automatically reload. So the table still shown the row that i have deleted.
I need to click 'clear' button instead to reload the content of the table.

can you advise me in which part i missing / wrong ?

here is my jsp again :


<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="/WEB-INF/tld/jmesa.tld" prefix="jmesa"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>


</head>
<body>
<form:form method="get" name="contactListForm" action="${pageContext.request.contextPath}/contactListForm.html">
<!-- ${contacts} -->

<c:choose>
<c:when test="${isEmpty == 'true'}">
<h2>Contact Manager has no data !</h2>
</c:when>

<c:otherwise>
${contacts}
</c:otherwise>
</c:choose>

</form:form>


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

</body>
</html>



here is my controller :

@RequestMapping(value = "contactListForm", method = RequestMethod.GET)
public ModelAndView getContactListForm(HttpServletRequest request, HttpServletResponse response) {
ModelAndView mv = new ModelAndView("contactList");

listOfContacts = findAllContacts();

TableModel tableModel = new TableModel("contactModel", request);
tableModel.setItems(listOfContacts);
tableModel.setEditable(true);

        tableModel.saveWorksheet(new WorksheetSaver() {
public void saveWorksheet(Worksheet worksheet) {
saveWorksheetChanges(worksheet);
}
});

HtmlTable htmlTable = new HtmlTable();
htmlTable.caption("Contacts Manager");

// non-fluent columns

HtmlRow htmlRow = new HtmlRow();
htmlRow.setUniqueProperty("contactId");

HtmlColumn remove = new HtmlColumn("remove");
remove.setWidth("5%");
remove.setWorksheetEditor(new RemoveRowWorksheetEditor());
remove.setTitle("&nbsp;");
remove.setFilterable(false);
remove.setSortable(false);
htmlRow.addColumn(remove);

HtmlColumn firstName = new HtmlColumn("firstName").title("First Name");
htmlRow.addColumn(firstName);

HtmlColumn lastName = new HtmlColumn("lastName").title("Last Name");
htmlRow.addColumn(lastName);

HtmlColumn email = new HtmlColumn("email");
htmlRow.addColumn(email);

HtmlColumn telephone = new HtmlColumn("telephone");
htmlRow.addColumn(telephone);

htmlRow.setSortable(true);
htmlRow.setFilterable(true);

htmlTable.setRow(htmlRow);
tableModel.setTable(htmlTable);

String html = tableModel.render();

mv.addObject("contacts", html);

return mv;
}


private void saveWorksheetChanges(Worksheet worksheet) {
logger.info("=====> ContactController.saveWorksheetChanges is invoked !");
String uniquePropertyName = WorksheetUtils.getUniquePropertyName(worksheet);
final List<String> uniquePropertyValues = WorksheetUtils.getUniquePropertyValues(worksheet);

logger.info("=====> uniquePropertyName : " + uniquePropertyName);

worksheet.processRows(new WorksheetCallbackHandler() {
public void process(WorksheetRow worksheetRow) {
if (worksheetRow.getRowStatus().equals(WorksheetRowStatus.ADD)) {
// do something to insert into table

} else if (worksheetRow.getRowStatus().equals(WorksheetRowStatus.REMOVE)) {
logger.info("=====> Remove data from table !");

try {
for (String value : uniquePropertyValues) {
logger.info("=====> contact with id : " + value + " will be removed !");
serviceLocator.getContactService().batchDeleteContactById(uniquePropertyValues);
}
} catch (Exception e) {
logger.error("=====> ContactController.saveWorksheetChanges.processRows-REMOVE is error!", e);
}

} else if (worksheetRow.getRowStatus().equals(WorksheetRowStatus.MODIFY)) {
// do something to update the table
}
}

}

});
}


regards.

Jeff Johnston

unread,
May 8, 2012, 3:53:52 PM5/8/12
to jm...@googlegroups.com
Call the tableModel.setAllItems() method. That is a callback method so that the save happens before the items are retrieved.

Also to use the worksheet you do not have to use the api to build your table. If you use the tag library then just use the TableModelUtils. Whatever works best for you.

-Jef



--
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/-/2l2iSl4fypUJ.

ryLuis

unread,
May 8, 2012, 11:35:56 PM5/8/12
to jm...@googlegroups.com
hi Jeff,

i have solved the problem, i think you meant is this function :

tableModel.setItems(new AllItems(){
   public Collection<?> getItems() {

return null;
   }
});


big thanks for you guide Jeff, jMesa ROCKS  !!!

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