不,不可能在 EL 方法表达式中使用变量参数,更不用说 EL 函数了。
最好的选择是使用不同数量的固定参数创建多个不同的命名方法。
public static boolean isValueIn2(Integer value, Integer option1, Integer option2) {}
public static boolean isValueIn3(Integer value, Integer option1, Integer option2, Integer option3) {}
public static boolean isValueIn4(Integer value, Integer option1, Integer option2, Integer option3, Integer option4) {}
// ...
作为一种可疑的替代方案,您可以传递一个逗号分隔的字符串并将其在方法内拆分
#{webUtilMB.isValueIn(OtherBean.category.id, '2,3,5')}
甚至是由以下命令创建的字符串数组fn:split()
在逗号分隔的字符串上
#{webUtilMB.isValueIn(OtherBean.category.id, fn:split('2,3,5', ','))}
但无论哪种方式,您仍然需要将它们解析为整数,或者将传入的整数转换为字符串。
如果您已经使用 EL 3.0,您还可以使用新的EL 3.0 集合语法 http://docs.oracle.com/javaee/7/tutorial/jsf-el004.htm无需整个 EL 功能。
#{[2,3,5].contains(OtherBean.category.id)}