简体   繁体   English

如何将下拉列表的选定值从xhtml页面传递到jsf bean?

[英]How to pass the selected value of dropdown list from xhtml page to jsf bean?

I have a dropdown list in my wep page, here it is: 我的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>

Then by clicking the button, i will go to Events.java bean and will process some info there. 然后通过单击按钮,我将转到Events.java bean并在那里处理一些信息。 But i need the values of these dropdown lists in the function createAccount(). 但是我需要在createAccount()函数中这些下拉列表的值。 Here is my Events bean 这是我的活动bean

@Named(value = "events")
@Dependent
public class Events {

/**
 * Creates a new instance of Events
 */
public Events() {
}

public void createAccount(){

}
}

How can i do this? 我怎样才能做到这一点?

Thanks 谢谢

This is a very basic JSF point, in your selectOneMenu component, define a value in your managed bean: 这是一个非常基本的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>

Now in your managed bean, you just define a property currency : 现在,在托管bean中,您只需定义一个属性currency

private String currency;

public String getCurrency() {
    return currency;
}
public void setCurrency(String currency) {
    this.currency = currency;
}

Now in your Events managed bean's method createAccount you just use the defined currency value. 现在,在Events托管bean的方法createAccount您仅使用定义的currency值。
Please refer to here for more examples and tutorials: https://stackoverflow.com/tags/jsf/info 请参考此处以获取更多示例和教程: https : //stackoverflow.com/tags/jsf/info

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM