我有一个数据表,其中第一个组件是删除按钮,最后一个是复选框。现在的问题是,当我删除一行时,它会重置另一行中选中的复选框,我不想取消选中另一行中选中的复选框。
<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;
}