How to call parameterized method from JSP using JSTL/EL -
how call java method arguments defined in java class, jsp using jstl/el. method returning arrays. return value can used.
you can invoke methods arguments in el if you're targeting , running servlet 3.0 compatible container (e.g. tomcat 7, glassfish 3, jboss 6, etc) web.xml
declared conform servlet 3.0. servlet version comes along el 2.2 allows invoking arbitrary instance methods arguments.
assuming you've ${bean}
in scope refers instance of class has method public object[] getarray(string key)
, should able this:
<c:foreach items="${bean.getarray('foo')}" var="item"> ${item} <br /> </c:foreach>
or variable argument
<c:foreach items="${bean.getarray(foo)}" var="item"> ${item} <br /> </c:foreach>
but if don't target servlet 3.0 container, cannot invoke methods arguments in el @ all. best bet job in preprocessing servlet suggested duffymo.
object[] array = bean.getarray("foo"); request.setattribute("array", array); // ...
as different alternative, create el function delegates method call. can find kickoff example somewhere near bottom of this blog. you'd end as:
<c:foreach items="${util:getarray(bean, 'foo')}" var="item"> ${item} <br /> </c:foreach>
with
public static object[] getarray(bean bean, string key) { return bean.getarray(key); }
Comments
Post a Comment