我是一名JSF新手并接管了一个现有项目。我通过模仿在另一个选项卡上完成的操作在UI中创建了一个新选项卡。除了有一个按钮(h:commandLink)删除显示列表中的一行数据外,所有工作都或多或少都有效。当我单击按钮时出现转换错误。分配给commandLink的动作功能甚至不被调用。我尝试过添加,但所有内容都是"转换错误",这对我来说或多或少是无用的。有人可以帮我找出调试转换错误的方法吗?
以下是我的jsp文件的片段:
<h:commandLink rendered="#{!surveyContactListListHandler.disableDelete && surveyContactListHandler.updateRendered}" styleClass="imageButtonLink deleteButton"
value="" action="#{surveyContactListListHandler.delete}">
<h:graphicImage styleClass="buttonImg" value="/images/_delete.gif" title="#{labels.deleteButtonLabel}">
</h:graphicImage>
</h:commandLink>
我的SurveyContactListListHandler派生自AbstractListHandler。这是相关功能,但正如我所说,它甚至从未被调用过,所以我不确定为什么它的相关性:
public abstract class AbstractListHandler extends AbstractHandler implements ListHandler
{
public String delete() {
try {
List idsToDelete = getCurrentIds();
// If there's just one id to delete, use the simpler version of the method
int numItemsToDelete = idsToDelete.size();
if ((numItemsToDelete == 1) && (((Integer) idsToDelete.get(0))).intValue() == getCurrentId()) {
return deleteOneRow(getCurrentId(), getCurrentDisplayIndex());
}
// delete all the ids
for (int i = 0; i < numItemsToDelete; i++) {
Integer idToDelete = (Integer) idsToDelete.get(i);
deleteItem(idToDelete.intValue());
}
// the wrapped data still has all the items including the
// deleted ones. Figure out which one to select next.
List dataList = (List) listDataModel.getWrappedData();
if (numItemsToDelete == dataList.size()) {
// all items were removed. no item is selected.
setCurrentId(-1);
} else {
// the logic is: if there are items after the last item
// to delete, select the one right after the last deleted index.
// if the last deleted item is also the last item in the list, find the
// last non-deleted item and select it.
// first we want to figure out tha last deleted index,
// last non-deleted index and the number of deleted items
// there are after the last non deleted index
int maxDeletedIndex = -1;
int maxNonDeletedIndex = -1;
int numDeletedItemsFound = 0;
for (int i = (getRealSize(dataList) - 1); i >= 0 ; i--) {
Object item = dataList.get(i);
int itemId = getItemId(item);
int itemIndex = getItemIndex(item);
if (idsToDelete.contains(new Integer(itemId))) {
// this item is one of the deleted items
numDeletedItemsFound ++;
if (maxDeletedIndex == -1) {
maxDeletedIndex = itemIndex;
if (maxNonDeletedIndex != -1) {
// We already found non deleted items
// which means this is the last deleted item
// and there are non-deleted items after this one
// we want to select the first item after the last
// deleted item
setCurrentId(getItemId(dataList.get(maxDeletedIndex + 1)));
break;
}
}
} else {
// this item is not one of the deleted items
if (maxNonDeletedIndex == -1) {
maxNonDeletedIndex = itemIndex;
if (maxDeletedIndex != -1) {
// We already found deleted items
// which means this is the last non-deleted item
// and there are only deleted items after this one
// we want to select the last non-deleted item
setCurrentId(itemId);
}
}
}
}
}
setReload(true);
return "deleted";
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
addMessage(null, e.getMessage());
return "error";
}
}
}