2013-08-29 54 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)或会话。

相关问题