未为h:selectBooleanCheckbox触发f:ajax侦听器 [英] f:ajax listener not fired for h:selectBooleanCheckbox

查看:86
本文介绍了未为h:selectBooleanCheckbox触发f:ajax侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该事件未在我的控制器中触发.这是代码.

The event doesn't get fired in my controller. This is the code.

查看:

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

提前谢谢!

R

我已经开始工作了,但是我仍然有问题,因为我有表格,所以我需要将表格包装在一个form标记中,因此将整个视图都封装在一个form标记中.我的目标只是将单击的复选框发送到服务器!该请求已发送到服务器,但未调用侦听器. javascript事件被调用.这是代码:

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:

查看:

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

对我来说解决这个问题很重要.

It's pretty important for me to solve this issue.

谢谢!

推荐答案

对解决方案的一些评论:

Some comments on the way to a solution:

您在ui:repeat中包含html表行.为此,您应该使用h:dataTable.

You have html table rows inside a ui:repeat. You should use a h:dataTable for this purpose.

h:selectBooleanCheckbox没有value属性.如果要调用操作方法,则最好使用h:commandLinkh:commandButton.然后,您就不需要f:attribute并可以执行以下操作:

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

在您的支持bean中:

And in your backing bean:

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

此外,每一行都有一个表单.桌子周围也许还有另一种包装形式.这将是无效的,并且可能是意外行为的可能原因.如果您使用的是Ajax,则只需在表格周围仅使用一种表单即可呈现/执行所需的部分.

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.

这篇关于未为h:selectBooleanCheckbox触发f:ajax侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆