HI 以下のコードは、選択した国に基づく列のない動的データテーブルを作成しました。ここで、選択した行を削除する各行の前にコマンド ボタンを追加します。テーブルを作成できますが、適切な場所にコマンド ボタンを追加できません。コマンドボタンを追加すると、行が1つ作成されます。
public void loadDynamicList() throws Exception {
int i = 0;
dynamicList = new ArrayList<List<String>>();
dynamicList.add(Arrays.asList(new String[] { "ID1" }));
existingCountryList = new ArrayList<Country>();
String countryCode = "US";
existingCountryList.add(getCountryService().getCountryByCode(
countryCode));
Country country = getCountryService().getCountryByCode(countryCode);
countryLanguageSet = country.getCountryLanguage();
i = country.getCountryLanguage().size();
dynamicHeaders = new String[i];
int j = 0;
for (CountryLanguage count : countryLanguageSet) {
System.out.println(count.getLanguage().getLanguageName());
dynamicHeaders[j] = count.getLanguage().getLanguageName();
j++;
}
}
public void populateDynamicDataTable() {
debugLogger.debug("populateDynamicDataTable:Enter");
// Create <h:dataTable value="#{myBean.dynamicList}" var="dynamicItem">.
HtmlDataTable dynamicDataTable = new HtmlDataTable();
dynamicDataTable.setValueExpression(
"value",
createValueExpression(
"# {relationBean.dynamicList}",
List.class));
dynamicDataTable.setVar("dynamicItem");
// Iterate over columns.
for (int i = 0; i < dynamicHeaders.length; i++) {
// Create <h:column>.
HtmlColumn column = new HtmlColumn();
dynamicDataTable.getChildren().add(column);
// Create <h:outputText value="dynamicHeaders[i]"> for <f:facet
// name="header"> of column.
HtmlOutputText header = new HtmlOutputText();
header.setValue(dynamicHeaders[i]);
column.setHeader(header);
HtmlInputText input = new HtmlInputText();
column.getChildren().add(input);
}
dynamicDataTableGroup = new HtmlPanelGroup();
dynamicDataTableGroup.getChildren().add(dynamicDataTable);
debugLogger.debug("populateDynamicDataTable:Exit");
}
public HtmlPanelGroup getDynamicDataTableGroup() throws Exception {
// This will be called once in the first RESTORE VIEW phase.
if (dynamicDataTableGroup == null) {
loadDynamicList(); // Preload dynamic list.
populateDynamicDataTable(); // Populate editable datatable.
}
return dynamicDataTableGroup;
}
public List<List<String>> getDynamicList() {
return dynamicList;
}
public void setDynamicList(List<List<String>> dynamicList) {
this.dynamicList = dynamicList;
}
public void setDynamicDataTableGroup(HtmlPanelGroup dynamicDataTableGroup) {
this.dynamicDataTableGroup = dynamicDataTableGroup;
}
public ValueExpression createValueExpression(String valueExpression,
Class<?> valueType) {
FacesContext facesContext = FacesContext.getCurrentInstance();
return facesContext
.getApplication()
.getExpressionFactory()
.createValueExpression(facesContext.getELContext(),
valueExpression, valueType);
}