f:没有为h:selectBooleanCheckbox触发ajax监听器

时间:2012-03-12 16:14:13

标签: java jsf jsf-2 primefaces

事件不会在我的控制器中被触发。这是代码。

查看:

<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");
  }
}

提前致谢!

REDIT:

我有这个工作,但我仍然有问题,因为我有表,所以我需要将表包装在表单标签中,所以我将整个视图包含在表单标签中。我的目标是向服务器发送单击的复选框!请求将发送到服务器,但不会调用侦听器。调用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;
    }
}

解决这个问题对我来说非常重要。

谢谢!

1 个答案:

答案 0 :(得分:2)

对解决方案的一些评论:

ui:repeat中有html表格行。您应该使用h:dataTable来实现此目的。

h:selectBooleanCheckbox没有value属性。如果您想调用操作方法,最好使用h:commandLinkh:commandButton。然后你不需要f:attribute并且可以做这样的事情:

<h:commandLink value="Delete" action="#{controller.delete(trade)}"/>

在你的支持bean中:

public void delete(Trade trade) {
 // delete action
}

此外,每行都有一个表单。也许桌子周围还有另一种包装形式。这将是无效的,并且可能是意外行为的原因。如果您使用的是ajax,那么您只需在表格周围使用一个表格并渲染/执行您喜欢的部分。

相关问题