Passing string parameter to a function or method from xhtml

放肆的年华 提交于 2020-01-30 05:26:11

问题


I have a button that I'd like to render based on whether a function returns true or false.

The HTML:

<p:commandButton type="button" rendered="#{myBean.checkPermission(1)}" value="Create"  />

And the supporting bean:

public boolean checkPermission(String actionKey) {
...
}

The problem is that when I call checkPermission with a numeric parameter like

#{myBean.checkPermission(1)},

it works fine, but with I pass a String as a parameter, i.e.

#{myBean.checkPermission(ABC)}

, I get an empty string passed. Any idea why?


回答1:


You're not passing a String, instead an ABC variable that can't be understood by EL and your method will receive null value (thanks to BalusC for correct me). You should add apostrophes (') to tell the framework you're passing a String:

<p:commandButton type="button" rendered="#{myBean.checkPermission('ABC')}"
    value="Create" />


来源:https://stackoverflow.com/questions/13463016/passing-string-parameter-to-a-function-or-method-from-xhtml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!