我需要將選定的值返回給bean進行進一步處理,但它的返回空值。選擇一個菜單返回Null值在Backing bean中?
<h:form>
<h:panelGrid columns="1">
<p:outputLabel id="state" value="State Name"></p:outputLabel>
<p:selectOneMenu id="statemenu" style="width:300px;"
value="#{MenuBean.state}">
<f:selectItem itemLabel="Select One"></f:selectItem>
<f:selectItems value="#{MenuBean.stateList}"></f:selectItems>
<p:ajax listener="#{MenuBean.stateChange}" update="dist"
process="@this" immediate="true"></p:ajax>
</p:selectOneMenu>
<br></br>
<p:outputLabel value="District"></p:outputLabel>
<p:selectOneMenu id="dist" style="width:300px;"
value="#{MenuBean.district}">
<f:selectItem itemLabel="Select One"></f:selectItem>
<f:selectItems value="#{MenuBean.districtList}"></f:selectItems>
</p:selectOneMenu>
</h:panelGrid>
<h:panelGrid style="position:relative; left:165px" columns="2"
cellpadding="2" cellspacing="2">
<p:commandButton value="Reset"
style='font-family: font-family : Baskerville, "Baskerville Old Face",
"Hoefler Text", Garamond, "Times New Roman", serif;;
font-size: 13px; font-weight: normal'></p:commandButton>
<p:commandButton value="Submit" immediate="true"
action="#{MenuBean.getValues}"
style='font-family: font-family : Baskerville, "Baskerville Old Face",
"Hoefler Text", Garamond, "Times New Roman", serif;;
font-size: 14px; font-weight: normal'></p:commandButton>
</h:panelGrid>
</h:form>
和背襯beaning是
私人字符串狀態;
private String district;
private Map<String,String> StateList = new HashMap<String,String>();;
private Map<String,String> DistrictList = new HashMap<String,String>();
public MenuBean() {
System.out.println("Entering the Constructor");
StateList = DBConnector.StateList();
// DistrictList = DBConnector.DistrictList();
}
public void stateChange() {
DistrictList = DBConnector.DistrictList();
}
public void getValues() {
System.out.println("getting the values");
System.out.println(getState());
System.out.println(getDistrict());
}
我編輯了代碼段,我猜它會給你一個洞察力。
您的組件是否在表單中? –
我做到了。但仍然不起作用 –
getValues()方法調用的很好嗎? – Omar