[英]How to pass the selected value of dropdown list from xhtml page to jsf bean?
我的wep頁面中有一個下拉列表,這里是:
<h:form>
<h:panelGrid columns="2">
<h:outputText value="Açılacak hesabın para birimi:"></h:outputText>
<h:selectOneMenu value="currency" >
<f:selectItem itemValue="choose" itemLabel="Seçiniz..." />
<f:selectItem itemValue="tl" itemLabel="Türk Lirası(TL)" />
<f:selectItem itemValue="usd" itemLabel="Amerikan Doları(USD)" />
<f:selectItem itemValue="euro" itemLabel="Euro" />
</h:selectOneMenu>
<h:outputText value="Açılacak hesabın cinsi:"></h:outputText>
<h:selectOneMenu value="vade" >
<f:selectItem itemValue="choose" itemLabel="Seçiniz..." />
<f:selectItem itemValue="vadesiz" itemLabel="Vadesiz mevduat hesabı" />
<f:selectItem itemValue="vadeli" itemLabel="Vadeli Mevduat Hesabı" />
</h:selectOneMenu>
<h:commandButton value="Onayla" action="#{events.createAccount}" ></h:commandButton>
</h:panelGrid>
</h:form>
然后通過單擊按鈕,我將轉到Events.java bean並在那里處理一些信息。 但是我需要在createAccount()函數中這些下拉列表的值。 這是我的活動bean
@Named(value = "events")
@Dependent
public class Events {
/**
* Creates a new instance of Events
*/
public Events() {
}
public void createAccount(){
}
}
我怎樣才能做到這一點?
謝謝
這是一個非常基本的JSF點,在selectOneMenu
組件中,在托管bean中定義一個值:
<h:selectOneMenu value="#{events.currency}" >
<f:selectItem itemValue="choose" itemLabel="Seçiniz..." />
<f:selectItem itemValue="tl" itemLabel="Türk Lirası(TL)" />
<f:selectItem itemValue="usd" itemLabel="Amerikan Doları(USD)" />
<f:selectItem itemValue="euro" itemLabel="Euro" />
</h:selectOneMenu>
現在,在托管bean中,您只需定義一個屬性currency
:
private String currency;
public String getCurrency() {
return currency;
}
public void setCurrency(String currency) {
this.currency = currency;
}
現在,在Events
托管bean的方法createAccount
您僅使用定義的currency
值。
請參考此處以獲取更多示例和教程: https : //stackoverflow.com/tags/jsf/info
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.