1
我想將所有網格面板存儲到一個數組列表中,以便我可以遍歷它們。但是,獲得的結果並不符合我的預期。使用Netbeans調試模式,我意識到無論添加到數組列表中的是哪個網格面板,它都與jsp綁定的值不同。通過綁定獲取提交的值
例如,(從調試模式)
Name Type Value
gridPanel1 HtmlPanelGrid #334
.
.
gridPanels ArrayList_ #323
[0] HtmlPanelGrid #524
的問題是,什麼是錯的?什麼是正確的方法來做到這一點?
JSP文件
<h:panelGrid binding="#{CreatePage.gridPanel1}" columns="10" id="gridPanel1" style="height: 100%" width="671">
<webuijsf:label for="column_TF1" id="columnLabel1" text="Column 1: "/>
<webuijsf:textField binding="#{CreatePage.column_TF1}" id="column_TF1" valueChangeListenerExpression="#{CreatePage.column_TF1_processValueChange}"/>
<webuijsf:label for="dataDropDown1" id="dataLabel1" text="Data Type: "/>
<webuijsf:dropDown binding="#{CreatePage.dataDropDown1}" id="dataDropDown1"
items="#{CreatePage.dataDropDown1DefaultOptions.options}"
onChange="webui.suntheme4_2.common.timeoutSubmitForm(this.form, 'mainGridPanel:columnGridPanel:gridPanel1:dataDropDown1');"
selected="#{CreatePage.dataDropDown1DefaultOptions.selectedValue}" valueChangeListenerExpression="#{CreatePage.dataDropDown1_processValueChange}"/>
<webuijsf:textField binding="#{CreatePage.charValueTF1}" columns="5" id="charValueTF1" rendered="false"/>
<webuijsf:label for="pkDropDown1" id="pkLabel1" text="Primary Key: "/>
<webuijsf:dropDown binding="#{CreatePage.pkDropDown1}" id="pkDropDown1"
items="#{CreatePage.pkDropDown1DefaultOptions.options}" onChange="" selected="#{CreatePage.pkDropDown1DefaultOptions.selectedValue}"/>
<webuijsf:label for="nullableDropDown1" id="nullableLabel1" text="Nullable:"/>
<webuijsf:dropDown binding="#{CreatePage.nullableDropDown1}" id="nullableDropDown1"
items="#{CreatePage.pkDropDown1DefaultOptions.options}" onChange=""
selected="#{CreatePage.pkDropDown1DefaultOptions.selectedValue}" valueChangeListenerExpression="#{CreatePage.nullableDropDown1_processValueChange}"/>
</h:panelGrid>
<h:panelGrid binding="#{CreatePage.gridPanel2}" columns="10" id="gridPanel2" style="height: 100%" width="671">
<webuijsf:label for="column_TF2" id="columnLabel2" text="Column 2: "/>
<webuijsf:textField binding="#{CreatePage.column_TF2}" id="column_TF2" valueChangeListenerExpression="#{CreatePage.column_TF2_processValueChange}"/>
<webuijsf:label for="dataDropDown2" id="dataLabel2" text="Data Type: "/>
<webuijsf:dropDown binding="#{CreatePage.dataDropDown2}" id="dataDropDown2"
items="#{CreatePage.dataDropDown1DefaultOptions.options}"
onChange="webui.suntheme4_2.common.timeoutSubmitForm(this.form, 'mainGridPanel:columnGridPanel:gridPanel2:dataDropDown2');" selected="#{CreatePage.dataDropDown1DefaultOptions.selectedValue}"/>
<webuijsf:textField binding="#{CreatePage.charValueTF2}" columns="5" id="charValueTF2" rendered="false"/>
<webuijsf:label for="pkDropDown2" id="pkLabel2" text="Primary Key: "/>
<webuijsf:dropDown binding="#{CreatePage.pkDropDown2}" id="pkDropDown2"
items="#{CreatePage.pkDropDown1DefaultOptions.options}" onChange="" selected="#{CreatePage.pkDropDown1DefaultOptions.selectedValue}"/>
<webuijsf:label for="nullableDropDown2" id="nullableLabel2" text="Nullable:"/>
<webuijsf:dropDown binding="#{CreatePage.nullableDropDown2}" id="nullableDropDown2"
items="#{CreatePage.pkDropDown1DefaultOptions.options}" onChange=""
selected="#{CreatePage.pkDropDown1DefaultOptions.selectedValue}" valueChangeListenerExpression="#{CreatePage.nullableDropDown1_processValueChange}"/>
</h:panelGrid>
的Java文件
List<HtmlPanelGrid> gridPanels = new ArrayList<HtmlPanelGrid>();
public HtmlPanelGrid getGridPanel1() {
return gridPanel1;
}
public void setGridPanel1(HtmlPanelGrid hpg) {
this.gridPanel1 = hpg;
}
private HtmlPanelGrid gridPanel2 = new HtmlPanelGrid();
public HtmlPanelGrid getGridPanel2() {
return gridPanel2;
}
public void setGridPanel2(HtmlPanelGrid hpg) {
this.gridPanel2 = hpg;
}
private HtmlPanelGrid gridPanel3 = new HtmlPanelGrid();
if (gridPanels.isEmpty()) {
gridPanels.add(gridPanel1);
gridPanels.add(gridPanel2);
gridPanels.add(gridPanel3);
gridPanels.add(gridPanel4);
gridPanels.add(gridPanel5);
gridPanels.add(gridPanel6);
}
for (int i = 0; i < gridPanels.size(); i++) {
TextField tempTF = (TextField) gridPanels.get(i).findComponent(("column_TF" + Integer.toString(i)));
// I always get null value
tempStr = (String) tempTF.getValue();
}
格式請。嘗試縮短問題。 – Nishant
凌亂的代碼。無法理解任何事情。 – Masudul
我認爲這使得代碼可讀:) –