jsf 2 - Invoke method with varargs in EL throws java.lang.IllegalArgumentException: wrong number of arguments -


i'm using jsf 2.

i have method checks matching values list of values:

@managedbean(name="webutilmb") @applicationscoped public class webutilmanagedbean implements serializable{ ...  public static boolean isvaluein(integer value, integer ... options){     if(value != null){         for(integer option: options){             if(option.equals(value)){                 return true;             }         }     }     return false; }   ... } 

to call method in el tried:

#{webutilmb.isvaluein(otherbean.category.id, 2,3,5)} 

but gave me a:

severe [javax.enterprise.resource.webcontainer.jsf.context] (http-localhost/127.0.0.1:8080-5) java.lang.illegalargumentexception: wrong number of arguments

is there way execute such method el?

no, not possible use variable arguments in el method expressions, let alone el functions.

your best bet create multiple different named methods different amount of fixed arguments.

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) {} // ... 

as dubious alternative, pass commaseparated string , split inside method

#{webutilmb.isvaluein(otherbean.category.id, '2,3,5')} 

or string array created fn:split() on commaseparated string

#{webutilmb.isvaluein(otherbean.category.id, fn:split('2,3,5', ','))} 

but either way, you'd still need parse them integer, or convert passed-in integer string.

in case you're on el 3.0, use new el 3.0 collection syntax without need whole el function.

#{[2,3,5].contains(otherbean.category.id)} 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -