【发布时间】:2012-03-12 16:14:13
【问题描述】:
该事件不会在我的控制器中触发。这是代码。
查看:
<ui:repeat var="operation" value="#{trade.operationsSortList}">
<tr class="operations">
<th class="empty_cell"></th>
<td id="operation" class="operation_cell color">#{operation.operation}</td>
<td class="color">#{operation.time}</td>
<td class="color">#{operation.coment}</td>
<td class="color">
<h:form>
<h:selectBooleanCheckbox>
<f:ajax event="click" listener="#{controller.onDelete}" />
<f:attribute name="trade" value="#{trade}" />
</h:selectBooleanCheckbox>
</h:form>
</td>
</tr>
</ui:repeat>
控制器:
@ManagedBean
@RequestScoped
public class Controller
{
private ArrayList trades;
.....
.....
public void onDelete(AjaxBehaviorEvent event) {
Trade trade = (Trade) event.getComponent().getAttributes().get("trade");
}
}
提前致谢!
重新编辑:
我得到了这个工作,但我仍然有问题,因为我有表格,所以我需要将表格包装在一个表单标签中,所以我将整个视图包含在一个表单标签中。我的目标只是将单击的复选框发送到服务器!请求被发送到服务器,但监听器没有被调用。 javascript 事件被调用。这是代码:
查看:
<h:form>
<table id="trades">
<th class="image_cell"></th>
<th>Type</th>
<th>Portfolio</th>
<ui:repeat var="trade" value="#{controller.errorTrades}">
<tr class="trade error">
<td class="image_cell error"><h:graphicImage styleClass="expandable" url="resources/images/plus.png"></h:graphicImage></td>
<td id="type" class="error">#{trade.type}</td>
<td class="error">#{trade.portfolio}</td>
</tr>
<tr class="operations">
<td id="#{trade.murexId}" class="operation_row" colspan="4">
<table id="operations">
<tr class="header">
<th class="empty_cell"></th>
<th class="operation_cell">Operation</th>
<th>Time Transaction</th>
<th>Comment</th>
<th id="delete">Delete</th>
</tr>
<ui:repeat var="operation" value="#{trade.operationsSortList}">
<tr class="operation">
<th class="empty_cell"></th>
<td id="operation" class="operation_cell color">#{operation.operation}</td>
<td class="color">#{operation.time}</td>
<td class="color">#{operation.coment}</td>
<td class="color checkbox">
<h:selectBooleanCheckbox title="delete">
<f:ajax execute="@this" event="click" listener="#{controller.onDelete}" onevent="onDeleteProcess" />
<f:attribute name="murexId" value="#{trade.murexId}" />
<f:attribute name="operationId" value="#{operation.id}" />
</h:selectBooleanCheckbox>
</td>
</tr>
</ui:repeat>
</table>
</td>
</tr>
</ui:repeat>
</table>
</h:form>
控制器:
@ViewScoped
public class Controller
{
private ArrayList trades;
private ArrayList errorTrades = new ArrayList();
.......code
public boolean onDelete(AjaxBehaviorEvent event)
{
long murexId = 0;
BigDecimal operationId = null;
boolean result = false;
Trade trade;
Iterator itop;
Operation operation;
......code
return true;
}
}
解决这个问题对我来说非常重要。
谢谢!
【问题讨论】:
-
什么 JSF impl/version?我无法在 Mojarra 2.1.7 上重现您的问题。但是我记得早期版本中的 ui:repeat+f:ajax inconsitenties。
-
既然你接受了马特的回答,我可以假设你的问题已经解决了吗?但是您提到您不想使用命令链接。真正的问题到底是什么,你到底是如何解决的?或者,如果没有解决,请编辑您的问题以包含一个完整的 SSCCE。这是尽可能小但完整的代码 sn-p,我们可以直接复制'n'paste'n'run 来查看问题。只要 你 仍然可以重现问题,请尽可能多地删除不相关的标签/属性,例如
<tr>、<td>等。然后在此处复制粘贴整个视图和 bean。 -
是的,我解决了。我在
标记中只放了一个
标签: java jsf jsf-2 primefaces