Java 如何在JSF2/EL2.2中使用可选参数列表调用方法
知道如何(如果可能的话)从JSF页面用可选参数调用java方法吗? Iam使用Java7、JSF2.1、EL2.2(Glassfish 3.1.2)。先谢谢你 我得到了这个例外Java 如何在JSF2/EL2.2中使用可选参数列表调用方法,java,jsf-2,el,optional-parameters,optional-arguments,Java,Jsf 2,El,Optional Parameters,Optional Arguments,知道如何(如果可能的话)从JSF页面用可选参数调用java方法吗? Iam使用Java7、JSF2.1、EL2.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 v
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')}"/>
属性示例
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.
EL中不支持Varargs 至于你的具体功能需求,你完全错了。您不应该在JSF中重新发明国际化/本地化,而应该使用JSF提供的工具。为此,您应该在
faces config.xml
或Facelets文件中使用
。这将通过API加载文件,并使用API格式化消息。然后可以使用设置字符串的格式
例如com/example/i18n/text.properties
key.en.currentDate=今天是{0},当前时间是{1}。
key.en.currentTime=当前时间为{0}。
视图:
此外,我不确定键中的en
是否代表英语,但如果它确实代表语言,那么你又犯了一个错误。不同的语言需要有各自的属性
文件,如文本属性
,文本属性
等符合API规则
另见:
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.