JSFページからオプションのパラメータを使用してJavaメソッドを呼び出す方法(可能であれば)はありますか? Java 7、JSF 2.1、EL 2.2 (Glassfish 3.1.2) を使用しています。前もって感謝します...
私はこの例外を得ました
javax.el.ELException: /example.xhtml: wrong number of arguments
Caused by: java.lang.IllegalArgumentException: wrong number of arguments
ページの例
<h:outputText value="#{bean.methodWithParameters('key.en.currentDate', '2012-01-01', '00:00')}"/>
<h:outputText value="#{bean.methodWithParameters('key.en.currentTime', '12:00')}"/>
豆の例
public String methodWithParameters(String key, Object ... params) {
String langValue = LanguageBean.translate(key);
return String.format(langValue, params);
}
プロパティの例
key.en.currentDate=Today is %s and current time is %s.
key.en.currentTime=Current time is %s.
key.en.currentDate=Today is %1$s and current time is %2$s.
key.en.currentTime=Current time is %2$s.