yrazlik
yrazlik

Reputation: 10777

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:

 <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. But i need the values of these dropdown lists in the function createAccount(). Here is my Events 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

Upvotes: 0

Views: 10235

Answers (1)

Laabidi Raissi
Laabidi Raissi

Reputation: 3333

This is a very basic JSF point, in your selectOneMenu component, define a value in your managed 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:

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.
Please refer to here for more examples and tutorials: https://stackoverflow.com/tags/jsf/info

Upvotes: 1

Related Questions