Reputation: 233
The event doesn't get fired in my controller. This is the code.
View:
<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>
Controller:
@ManagedBean
@RequestScoped
public class Controller
{
private ArrayList trades;
.....
.....
public void onDelete(AjaxBehaviorEvent event) {
Trade trade = (Trade) event.getComponent().getAttributes().get("trade");
}
}
Thanks in advance!
REDIT:
I got this working, but I still have problems because I have tables, so I need to wrap the tables in a form tag, so I enclose the whole view in a form tag. My goal is just to send to the server the clicked checkbox! The request is sent to the sever, but the listener doesn't get called. The javascript event gets called. This is the code:
VIEW:
<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>
CONTROLLER:
@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;
}
}
It's pretty important for me to solve this issue.
Thanks!
Upvotes: 1
Views: 3511
Reputation: 30025
Some comments on the way to a solution:
You have html table rows inside a ui:repeat
. You should use a h:dataTable
for this purpose.
The h:selectBooleanCheckbox
has no value
attribute. If you want to call an action method you should better use a h:commandLink
or h:commandButton
. Then you wouldn't need the f:attribute
and could do something like this:
<h:commandLink value="Delete" action="#{controller.delete(trade)}"/>
And in your backing bean:
public void delete(Trade trade) {
// delete action
}
Furthermore you have one form for each row. Maybe there is another wrapping form around the table. This wouldn't be valid and would be the possible cause of unexpected behavior. If you are using ajax you simply could use only one form around the table and render/execute the parts you like.
Upvotes: 2