如代码所示,我有几个嵌套表。当用户单击复选框时,ajax 调用被发送到服务器,然后返回到客户端。如果服务器中的进程正常工作,则在获取回调时,使用 jquery 从 html 代码中删除单击的操作行。然后,当用户尝试删除同一操作表中的另一行时,发送到服务器的值不正确。该调用发送下一行值:#{trade.murexId}、#{operation.id} 和 #{operation.operation},但不是正确的。Javascript 和 jquery 回调函数工作正常。我正在使用最新版本的 Mojarra。为什么会这样?我该如何解决?
HTML:
<table id="trades">
<th class="image_cell"></th>
<th>Murex Id</th>
<th>Type</th>
<th>Portfolio</th>
<th>Log</th>
<ui:repeat var="trade" value="#{controller.errorTrades}">
<h:form>
<tr class="trade error">
<td class="image_cell error"><h:graphicImage styleClass="expandable" url="resources/images/plus.png"></h:graphicImage></td>
<td id="murex_id" class="error">#{trade.murexId}</td>
<td id="type" class="error">#{trade.type}</td>
<td class="error">#{trade.portfolio}</td>
<td class="error">
<h:commandButton image="resources/images/log_big.jpg" action="#{controller.onLogTrade(trade.murexId)}">
<f:ajax render="log_big" />
</h:commandButton>
<h:panelGroup id="log_big">
<h:outputScript rendered="#{not empty controller.result}">
onLogProcess("#{controller.result}");
</h:outputScript>
</h:panelGroup>
</td>
</tr>
<tr class="operations">
<td id="#{trade.murexId}" class="operation_row" colspan="5">
<table id="operations">
<tr class="header">
<th class="empty_cell"></th>
<th class="operation_cell">Operation</th>
<th>Murex Status</th>
<th>GBO Status</th>
<th>GBO Id</th>
<th>OPICS Id</th>
<th>Time Transaction</th>
<th>Comment</th>
<th id="delete">Delete</th>
<th>Log</th>
</tr>
<ui:repeat var="operation" value="#{trade.operationsSortDescList}" varStatus="status">
<tr class="operation">
<th class="empty_cell"></th>
<td id="operation" class="operation_cell color">#{operation.operation}</td>
<td class="color">#{operation.statusMurex}</td>
<td id="status_gbo" class="color">#{operation.statusGbo}</td>
<td id="gbo_id" class="color">#{operation.gboId}</td>
<td id="opics_id" class="color">#{operation.opicsId}</td>
<td class="color">#{operation.datetimeToString}</td>
<td class="color">#{operation.coment}</td>
<td class="color checkbox">
<h:selectBooleanCheckbox>
<f:ajax execute="@form" event="click" listener="#{controller.onDelete}" onevent="onDeleteProcess" />
<f:attribute name="murexId" value="#{trade.murexId}" />
<f:attribute name="operationId" value="#{operation.id}" />
<f:attribute name="operation" value="#{operation.operation}" />
</h:selectBooleanCheckbox>
</td>
<td class="color log">
<h:commandButton image="resources/images/log_small.jpg" action="#{controller.onLogOperation(operation)}">
<f:ajax execute="@form" render="small_log" />
</h:commandButton>
<h:panelGroup id="small_log">
<h:outputScript rendered="#{not empty controller.result}">
onLogProcess("#{controller.result}");
</h:outputScript>
</h:panelGroup>
</td>
</tr>
</ui:repeat>
</table>
</td>
</tr>
</h:form>
</ui:repeat>
</table>
提前致谢!
重新编辑:
我将 h:selectBooleanCheckbox 更改为 h:commandButton。
看法:
<table id="operations">
<tr class="header">
<th class="empty_cell"></th>
<th class="operation_cell">Operation</th>
<th>Murex Status</th>
<th>GBO Status</th>
<th>GBO Id</th>
<th>OPICS Id</th>
<th>Time Transaction</th>
<th>Comment</th>
<th id="delete">Delete</th>
<th>Log</th>
</tr>
<ui:repeat var="operation" value="#{trade.operationsSortDescList}" varStatus="status">
<tr class="operation">
<th class="empty_cell"></th>
<td id="operation" class="operation_cell color">#{operation.operation}</td>
<td class="color">#{operation.statusMurex}</td>
<td id="status_gbo" class="color">#{operation.statusGbo}</td>
<td id="gbo_id" class="color">#{operation.gboId}</td>
<td id="opics_id" class="color">#{operation.opicsId}</td>
<td class="color">#{operation.datetimeToString}</td>
<td class="color">#{operation.coment}</td>
<td class="color checkbox">
<h:commandButton image="resources/images/log_small.jpg" action="#{controller.onDelete(operation)}">
<f:ajax execute="@form" render="small_log" onevent="onDeleteProcess" />
</h:commandButton>
</td>
<td class="color log">
<h:commandButton image="resources/images/log_small.jpg" action="#{controller.onLogOperation(operation)}">
<f:ajax execute="@form" render="small_log" />
</h:commandButton>
<h:panelGroup id="small_log">
<h:outputScript rendered="#{not empty controller.result}">
onLogProcess("#{controller.result}");
</h:outputScript>
</h:panelGroup>
</td>
</tr>
</ui:repeat>
</table>
控制器:
public void onDelete(Operation operation)
{
Trade trade = operation.getTrade();
Boolean result = false;
try {
if (trade.getOperations().size() == 1) {
result = Modelo.deleteTrade(trade);
if (result)
this.trades.remove(trade);
} else {
result = Modelo.deleteOperation(operation);
if (result)
trade.getOperations().remove(operation);
}
} catch(Exception ex) {
ConfigUtil.LOGGER.error(ex);
}
}
当我删除一个操作时,这就是问题所在。没有,因为 jquery。我对此很确定,因为我测试过它。当我删除一个操作并单击下一个操作时,它会向服务器发送错误的操作。知道为什么会这样吗?
谢谢!