質問
アクション ハンドラー内からフォーム フィールドの ID を確認する必要があります。フィールドは含まれる facelets コンポーネントの一部であるため、形式は異なります。
付属.xhtml
<ui:component>
<h:inputText id="contained_field"/>
<h:commandButton actionListener="#{backingBean.update}" value="Submit"/>
</ui:component>
example_containing.xhtml
<h:form id="containing_form">
<ui:include src="/included.xhtml"/>
</h:form>
フォームの ID を確認するにはどうすればよいですか? update
実行時のメソッド?さらに良いのは、入力フィールドの ID を直接指定することです。
解決
ボタンをバッキング Bean にバインドし、最も近いフォームが見つかるまで getParent() を使用します。
他のヒント
プログラム的には jsight のメソッドを使用します。要素の ID は、それを見ることで知ることができます (JSF に要素を作成させない限り、ID に番号を付ける方法がわかりません)。h:form は名前付けコンテナなので、別の名前付けコンテナでラップしない限り、containedForm:containedfield になります。「:」は名前付け区切り文字で、デフォルトでは JSF であり、ID は大まかに言って次のように作成されます。 、(parentNamingContainerId:)*componentId
update メソッドは actionListener 型であるため、次のように UI コンポーネントにアクセスできます。
public void update(javax.faces.event.ActionEvent ac) {
javax.faces.component.UIComponent myCommand = ac.getComponent( );
String id = myCommand.getId(); // get the id of the firing component
..... your code .........
}
所属していません StackOverflow