私はJSFが初めてで、1か所で立ち往生しています。2 つの項目を含む 1 つのドロップダウン リストがあります。
銀行
現金
ここで、銀行を選択すると、他のドロップダウンに銀行に関連する項目が入力され、現金を選択すると、現金の項目が 2 番目のドロップダウンに表示されます。
JSFでそれを行う方法は? どこで変更を加える必要がありますか?
どんな助けでも大歓迎です.Thanks
私はJSFが初めてで、1か所で立ち往生しています。2 つの項目を含む 1 つのドロップダウン リストがあります。
銀行
現金
ここで、銀行を選択すると、他のドロップダウンに銀行に関連する項目が入力され、現金を選択すると、現金の項目が 2 番目のドロップダウンに表示されます。
JSFでそれを行う方法は? どこで変更を加える必要がありますか?
どんな助けでも大歓迎です.Thanks
まあ、あなたはjsf開発を改善するためにprimefacesを使うことができます
<p:selectOneMenu id="cboCountries" value="#{beanCountries.ValueSelected}" effect="fade">
<f:selectItem itemLabel="Select Country" itemValue="-1" /> //a default value
<f:selectItems value="#{beanCountries.listOfCountries}" var="countries" itemLabel="#{countries.name}" itemValue="#{countries.id}"/>
<p:ajax event="change" update="cboCities" listener="beanCountries.listCities()"/> //notice "update" refresh an especific DOM Element of an especific ID
</p:selectOneMenu>
<p:selectOneMenu id="cboCities" value="#{beanCities.ValueSelected}" effect="fade">
<f:selectItem itemLabel="Select City" itemValue="-1" /> //a default value
<f:selectItems value="#{beanCities.listOfCities}" var="cities" itemLabel="#{cities.name}" itemValue="#{cities.id}"/> //this is when you want to put elements from DB or from an Array
</p:selectOneMenu>
" は、primefaces の特別なマークです。イベント = "change" は、最初の "ComboBox" から要素を選択することを呼び出します。その後、プロパティの更新によって 2 番目のコンボ ボックスが更新され、プロパティ "listener" が何の論理アクションを実行します。この場合、メソッド「listCities()」は「listOfCities」にDB o Arraysの値を入力します。
したがって、primefaces のない jsf では次のようになります。
<h:form>
<h:selectOneMenu value="#{beanCountries.ValueSelected}">
<f:selectItem itemLabel="Select Country" itemValue="-1" /> //a default value
<f:selectItems value="#{beanCountries.listOfCountries}" var="countries" itemLabel="#{countries.name}" itemValue="#{countries.id}"/>
</h:selectOneMenu>
<h:selectOneMenu id="cboCities" value="#{beanCities.ValueSelected}">
<f:selectItem itemLabel="Select City" itemValue="-1" /> //a default value
<f:selectItems value="#{beanCities.listOfCities}" var="cities" itemLabel="#{cities.name}" itemValue="#{cities.id}"/> //this is when you want to put elements from DB or from an Array
</h:selectOneMenu>
<h:commandButton value="Submit" action="beanCountries.listCities()"/>
</h:form>
この方法はボタン (jsf) を使用し、アクション プロパティは Java メソッドを実行してからページを更新します。これは、selectOneMenu コンポーネントの「ValueChangeListener」プロパティによっても作成できます。