Jsf 从xhtml向函数或方法传递字符串参数
我有一个按钮,我想根据函数是否返回true或false来呈现它 HTML:Jsf 从xhtml向函数或方法传递字符串参数,jsf,el,Jsf,El,我有一个按钮,我想根据函数是否返回true或false来呈现它 HTML: <p:commandButton type="button" rendered="#{myBean.checkPermission(1)}" value="Create" /> public boolean checkPermission(String actionKey) { ... } 问题是当我用一个数字参数调用checkPermission时 {myBean.checkPermission(1)
<p:commandButton type="button" rendered="#{myBean.checkPermission(1)}" value="Create" />
public boolean checkPermission(String actionKey) {
...
}
问题是当我用一个数字参数调用checkPermission时
{myBean.checkPermission(1)}
它工作得很好,但是我将字符串作为参数传递,即
{myBean.checkPermission(ABC)}
,我传递了一个空字符串。知道为什么吗?您没有传递
字符串,而是传递EL无法理解的ABC
变量,您的方法将收到null
值(感谢BalusC提供的更正信息)。您应该添加撇号('),告诉框架您正在传递一个字符串
:
<p:commandButton type="button" rendered="#{myBean.checkPermission('ABC')}"
value="Create" />
更确切地说,是EL不理解它。变量#{ABC}
在EL范围中不存在,计算结果为null
。这超出了JSF的控制范围。