0

Webページにドロップダウンリストがあります。これは次のとおりです。

 <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(){

}
}

これどうやってするの?

ありがとう

4

1 に答える 1

1

これは非常に基本的な 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;
}

マネージドEventsBean のメソッドcreateAccountでは、定義されたcurrency値を使用するだけです。その他の例とチュートリアルについては、 https
://stackoverflow.com/tags/jsf/info を参照してください。

于 2013-07-04T09:34:46.837 に答える