2011-09-09 13 views
6

JSF 2.1仕様のセクション3.1.4には、のすべての属性が標準コンポーネントの値式有効であると記載されています。JSF 2.1 ValueExpression in action-attribute

私はのcommandButtonのaction属性に値式を割り当てる:

<h:commandButton value="OK" action="#{myBean.valExp}" /> 

私もBeanのクラスでgetValExpとsetValExpメソッドを定義し、対応します。

しかし、私のJSF実装(JBoss 6)はその式をメソッド式にするため、valExp()メソッドがないため「メソッドが見つかりません」というエラーが発生します。

私は間違ったことをしていますか仕様があまりにもお粗末で実際にすべてを意味するのではなく、メソッド以外の表現属性だけですか?または私は仕様を誤解していますか?

[備考:この質問の理由は、実際の技術的な問題ではありませんが、私は、値やメソッドの表現の違いを理解しようとしている。]

答えて

8

値の式は、パブリックgetter/setterメソッドによって公開されるプロパティにバインドされています。

<h:inputText value="#{bean.value}" /> 

これはpublic T getValue()public void setValue(T value)方法が必要です。文字通り全く同じ名前のprivate T value;プロパティの存在がではなく、であることに注意してください。 <h:outputText>,<h:dataTable>,<f:selectItems>などの純粋な出力コンポーネントでは、セッターメソッドもではなく、必須です。

メソッド式は、非ゲッター/セッターメソッド(「アクション」メソッド)にバインドされています。

<h:commandButton value="submit" action="#{bean.submit}" /> 

これはTは、最終的にvoidすることができ、この方法は、最終的には、属性のメソッド式の署名に応じて、追加の引数を取ることができpublic T submit()方法が必要です。 view declaration language documentationの正確な詳細は、たとえば<h:inputText><h:commandButton><f:ajax>のようになります。ここ<h:commandButton>actionactionListener属性定義のエキスです:

Name:  action 
Type:  javax.el.MethodExpression (signature must match java.lang.Object 
      action()) 
Description: MethodExpression representing the application action to invoke when 
      this component is activated by the user. The expression must 
      evaluate to a public method that takes no parameters, and returns an 
      Object (the toString() of which is called to derive the logical 
      outcome) which is passed to the NavigationHandler for this 
      application. 

Name:  actionListener 
Type:  javax.el.MethodExpression (signature must match void 
      actionListener(javax.faces.event.ActionEvent))  
Description: MethodExpression representing an action listener method that will be 
      notified when this component is activated by the user. The 
      expression must evaluate to a public method that takes an 
      ActionEvent parameter, with a return type of void, or to a public 
      method that takes no arguments with a return type of void. In the 
      latter case, the method has no way of easily knowing where the event 
      came from, but this can be useful in cases where a notification is 
      needed that "some action happened". 

はい、私はスペックはすべてサポート値式を属性と述べるにややずさんであることに同意します。一般に、実際には、すべての属性が#{}のように式言語をサポートしていることを意味します。一方、メソッド式は、ちょうど「特別な」値式であるかのように解釈することもできますが、正確にはそうではありません。私はいくつかの混乱を解決する要求でこれに関する仕様書の問題報告を投稿しました:issue 1036

+0

値式の代わりにメソッド式を割り当てることはできますか?私。 '' –

+0

@ St.Antario:http://stackoverflow.com/search?q=javax.el.propertynotwritableexception+h%3Ainputtext – BalusC

+0

だから、意味がないので、短い答えはいいえ.... –

関連する問題