2013-08-29 75 views
0

我有一個數據表,其中第一個組件是刪除按鈕,最後是複選框。 現在的問題是,當我刪除一行它重置在其他行中選擇的複選框 我不想取消選中其他行中的複選框。從數據表中刪除而不影響複選框事件

<h:dataTable id="languageTableBody" value="#{countryBean.countryLanguageList}" var="countryLangObj" > 
     <h:column> 
      <f:facet name="header">#{msg['country.language.label.delete']}</f:facet> 
      <p:commandLink action="#{countryBean.deleteRow}" immediate="true" update="@form" process="@this"> 
       <h:graphicImage value="../images/delete.png" /> 
       <f:setPropertyActionListener target="#{countryBean.langId}" value="#{countryLangObj.language.languageCode}" /> 
      </p:commandLink> 
     </h:column> 
     <h:column> 
      <f:facet name="header">#{msg['country.language.label.assignlanguage']}</f:facet> 
      <h:inputText readonly="true" value="#{countryLangObj.language.languageName}" id="languageName" /> 
     </h:column> 

     <h:column> 
      <f:facet name="header">#{msg['country.language.label.languagecode']}</f:facet> 
      <h:inputText readonly="true" value="#{countryLangObj.language.languageCode}" /> 
     </h:column> 
     <h:column> 
      <f:facet name="header">#{msg['country.language.label.defaultlanguage']}</f:facet> 
      <h:selectBooleanCheckbox id="checkBox" value="#{countryLangObj.isDefaultLanguage}" onclick="dataTableSelectOneRadio(this)" /> 

     </h:column> 
    </h:dataTable> 

countryBean.java

public String deleteRow(){ 
    System.out.println("deleteRow()::Enter"); 
    String delLangId = getLangId(); 
    System.out.println("getLangId(): "+getLangId()); 
    if(null != delLangId && delLangId.trim().length() > 0){ 
     System.out.println("Delete Language Code: "+delLangId); 
     List<CountryLanguageDTO> countryLangList = getCountryLanguageList(); 
     System.out.println("countryLangList: "+ (null == countryLangList)); 
     List<CountryLanguageDTO> tempCountryLangList = new ArrayList<CountryLanguageDTO>(); 
     for (CountryLanguageDTO countryLanguage : countryLangList) { 
      System.out.println("wewewewew: "+delLangId.equalsIgnoreCase(countryLanguage.getLanguage().getLanguageCode())); 
      if(!delLangId.equalsIgnoreCase(countryLanguage.getLanguage().getLanguageCode())){ 
       tempCountryLangList.add(countryLanguage); 
      } 
     } 
     setCountryLanguageList(tempCountryLangList); 
    } 
    return SUCCESS; 
} 

addCountry.js

function dataTableSelectOneRadio(radio) { 
var id = radio.name.substring(radio.name.lastIndexOf(':')); 
var el = radio.form.elements; 
for (var i = 0; i < el.length; i++) { 
    if (el[i].name.substring(el[i].name.lastIndexOf(':')) == id) { 
     el[i].checked = false; 
    } 
} 
radio.checked = true; 

}

回答

1

它發生,因爲這樣的:

<p:commandLink action="#{countryBean.deleteRow}" immediate="true" update="@form" process="@this"> 

當點擊該按鈕,您將發送形式的複選框。但由於process="@this"你不會轉換/驗證/存儲任何輸入。唯一會被處理的是按鈕本身。之後,由於update="@form"整個表單(包括帶有複選框的表格)將被重新渲染。但用舊的值。

因此,解決方案是要麼將process="@this"更改爲@form,要麼在每次更改值時添加Ajax功能以存儲每個複選框的新值。

0

這可能是豆範圍問題。如果情景如下: 先決條件: - 表僅顯示。 場景: - 選擇一些複選框。 - 刪除行 當前結果 - 未選中複選框。

因此,在刪除行之後,您可以重新查看視圖,以便所有數據都獲得默認狀態。 嘗試將您的範圍更改爲查看(CDI)或會話。

相關問題