从xhtml将字符串参数传递给函数或方法 [英] Passing string parameter to a function or method from xhtml

查看:106
本文介绍了从xhtml将字符串参数传递给函数或方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要根据函数返回true或false来渲染的按钮.

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

HTML:

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

还有支持bean:

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

问题是,当我使用

#{myBean.checkPermission(1)}

它工作正常,但是我将String作为参数传递,即

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?

推荐答案

您没有传递String,而是传递了EL无法理解的ABC变量,并且您的方法将接收null值(感谢BalusC纠正我).您应该添加撇号(')来告诉框架您正在传递String:

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" />

这篇关于从xhtml将字符串参数传递给函数或方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆