我正在使用JSF,希望有一个仅在关联的受管bean中的String的值大于零时才应呈现的组件。我正在这样做:
rendered="#{tabbedToolbarBean.editor.selectedQuery.length() gt 0}"
此外,
selectedQuery
的getter签名是public String getSelectedQuery(){}
。最新版本的weblogic服务器出现以下错误。Error: Function length has an invalid prefix or uses the default namespace which is not defined. Correct the prefix or in a jsp document, put the function inside a tag that defines the tag library namespace
我缺少什么?在谷歌搜索后没有得到太多帮助。
最佳答案
这意味着您的环境不支持调用带有括号的非getter方法的新EL 2.2功能。
最好的选择是使用JSTL的fn:length()
。
<html ... xmlns:fn="http://java.sun.com/jsp/jstl/functions">
...
rendered="#{fn:length(tabbedToolbarBean.editor.selectedQuery) gt 0}"
另外,只需在EL中使用
empty
关键字即可。不同之处在于,它还会检查无效性。rendered="#{not empty tabbedToolbarBean.editor.selectedQuery}"
也可以看看:
关于jsp - 检查表达式语言中的字符串长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15703965/