在EL表达中调用GET方法会导致转换错误
我的应用程序视图上有一个JSF隐藏的输入,该输入保存了一些对象的属性:
<h:inputHidden id="hidMyData" value="#{bean.myList.get(bean.listIndex).someAttr}" immediate="true"/>
确定正确对象的索引也保存在session bean中,并且是一个整数:
public void setListIndex(int listIndex) {
this.listIndex = listIndex;
}
public int getListIndex() {
return listIndex;
}
如果我在WebSphere Application上运行了我的应用程序服务器8.5.5,则遇到转换错误:
PrimeExceptio E /pages/MyView.xhtml at line 566 and column 50 value="#{bean.myList.get(bean.listIndex).someAttr}": Cannot convert get of type class java.lang.String to class java.lang.Integer
同时,如果我以IBM Portal 7上的portlet运行它,则没有错误。在这两种情况下,我都使用MyFaces实现版本2.0.17和PrimeFaces 6.2.27。
什么可能导致此错误?
EDIT1:刚刚意识到,使用方括号代替GET
方法可以正常工作:
<h:inputHidden id="hidMyData" value="#{bean.myList[bean.listIndex].someAttr}" immediate="true"/>
无论如何,如果某人有解释为什么此方法有效,而第一种方法不起作用,我将不胜感激。
I have a JSF hidden input on my app view that holds some object's attribute:
<h:inputHidden id="hidMyData" value="#{bean.myList.get(bean.listIndex).someAttr}" immediate="true"/>
Index that determines the right object, is also saved in session bean and is an integer:
public void setListIndex(int listIndex) {
this.listIndex = listIndex;
}
public int getListIndex() {
return listIndex;
}
If I run my app on Websphere Application Server 8.5.5, I'm getting a conversion error:
PrimeExceptio E /pages/MyView.xhtml at line 566 and column 50 value="#{bean.myList.get(bean.listIndex).someAttr}": Cannot convert get of type class java.lang.String to class java.lang.Integer
At the same time if I run it as a portlet on IBM Portal 7, there's no error. In both cases I use MyFaces implementation version 2.0.17 and Primefaces 6.2.27.
What could cause this error?
EDIT1: Just realized that using square brackets instead of get
method works fine:
<h:inputHidden id="hidMyData" value="#{bean.myList[bean.listIndex].someAttr}" immediate="true"/>
Anyway if someone has an explanation why this method works and the first one doesn't, I'll appreciate it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论