gee*_*daa 2 parameters jsf el javabeans
我无法使用参数进行方法调用以在JSF 2.0(MyFaces)和Tomcat 6中工作.
这是我尝试的方式:
<f:selectItems var="item" value="#{bla.someList}
itemValue="#{item.value1}"
itemLabel="#{item.value2}">
<f:param name="param1" value="0" />
</f:selectItems>
我无法定义这样的方法,对吗?那么为何不?
getSomeList(int a)
Run Code Online (Sandbox Code Playgroud)
所以这就是我的尝试:
getSomeList() {
Integer a = Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("param1"));
return doSomething(a);
}
Run Code Online (Sandbox Code Playgroud)
这就是我得到的:
java.lang.NumberFormatException: null
java.lang.Integer.parseInt(Integer.java:417)
Run Code Online (Sandbox Code Playgroud)
如果有人帮助我,我将非常感激.谢谢!
更新:啊,它适用于#{bla.getSomeList(0)}!
我无法定义这样的方法,对吗?
Run Code Online (Sandbox Code Playgroud)getSomeList(int a)
没有.
那么为何不?
因为您使用的旧Tomcat 6不支持引入此功能的EL 2.2.
这就是我得到的:
Run Code Online (Sandbox Code Playgroud)java.lang.NumberFormatException: null java.lang.Integer.parseInt(Integer.java:417)
因为它存在null.该<f:param>只,而不是简单的组件链接/按钮的作品.
为了使EL中的方法调用能够工作,您需要升级到支持Servlet 3.0/EL 2.2的容器(如Tomcat 7),或者将Tomcat 6的默认EL 2.1实现替换为支持参数化方法调用的实现.详细信息请参阅此答案.完成后,您可以使用
<f:selectItems value="#{bla.getSomeList(0)}" ... />
Run Code Online (Sandbox Code Playgroud)
另一种方法是替换List为Map,可以是一个自定义实现,它对方法进行(延迟)加载get().
public Map<String, List<Something>> getSomeMap() {
return someCustomLazyLoadingMap;
}
Run Code Online (Sandbox Code Playgroud)
同
<f:selectItems value="#{bla.someMap.keyName}" ... />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9953 次 |
| 最近记录: |