Passing string parameter to a function or method f

2019-02-24 09:17发布

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?

标签: jsf el
1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-02-24 09:31

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" />
查看更多
登录 后发表回答