2012-03-12 35 views
1

事件不會在我的控制器中被觸發。這是代碼。f:ajax監聽器沒有爲h啓動:selectBooleanCheckbox

查看:

<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事件被調用。這是代碼:

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> 

控制器:

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

爲我解決這個問題這是非常重要的。

謝謝!

+0

什麼是JSF impl/version?我無法在Mojarra 2.1.7上重現您的問題。不過我記得ui:在早期版本中重複+ f:ajax inconintenties。 – BalusC 2012-03-12 20:08:06

+0

我使用的是最新版本 – bribon 2012-03-13 01:50:53

+0

既然你接受了馬特的回答,我可以假設你的問題解決了嗎?但是你提到你不想使用命令鏈接。真正的問題究竟是什麼,你究竟如何解決它?或者如果它沒有解決,那麼請編輯您的問題以包含一個完整的SSCCE。這是**儘可能小,但完整的**代碼片段,我們可以通過copy'n'paste'n'run來查看問題。儘可能去除儘可能多的無關標籤/屬性,如'','​​'等,只要*你*仍然可以重現問題。然後在這裏複製整個視圖和bean。 – BalusC 2012-03-13 15:23:50

回答

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,你只能在表格周圍使用一種形式,並渲染/執行你喜歡的部分。

+0

我正在使用ui:因爲一個表格被包含在另一個表格中,因此有很多css。當我嘗試數據表時,我遇到了很多問題。我不想使用一個commandLink標籤。我曾經使用python框架,可以使用jquery和restful進行這種調用。沒有其他包裝形式。有沒有辦法像這樣做?或者我需要將所有標籤封裝在一個表單中?當然,我不想使用commandLike按鈕 – bribon 2012-03-13 02:00:10