EL方法中的参数 [英] Parameters in EL methods

查看:172
本文介绍了EL方法中的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在JSP中使用带有参数的EL的方法。但EL不支持方法中的参数。实际上我想显示一个表,它有一个输出一个单元格中的值列表的字段。对于每个单元格,此列表将不同,它取决于参数。我怎么能用EL做这个呢?

I want to use a method in JSP using EL that has a parameter. But EL doesn't support parameters in methods. Actually I want to show a table, which has a field that output a list of values in one cell. For every cell this list will be different, it depends on parameter. How can I do this using EL?

我试过这个,但是说​​它不能在
中将Integer转换成String < c:set var =groupvalue =$ {entrant.idGroup}/> 其中 entrant.idGroup 返回int值

I have tried this, but is says that it can not cast Integer to String in <c:set var="group" value="${entrant.idGroup}" /> where entrant.idGroup return int value

    <c:forEach var="entrant" items="${bean.entrants}">
                <tr>
            <td>${entrant.idEntrant}</td>
                    <c:set var="group" value="${entrant.idGroup}" />
                    <td><%=bean.getGroupCode(Integer.parseInt((String)pageContext.getAttribute("group")))%></td>
            <td>${entrant.name}</td>
     </c:forEach>

但即使它有效,我也想在JSP中使用纯EL。我怎样才能实现这个目标?

But even if it works, I want to use pure EL in JSP. How can I achieve this?

推荐答案

在EL 2.2中引入了对传递方法参数和调用非getter方法的支持,这是Servlet 3.0的一部分。因此,最好的办法是升级到兼容Servlet 3.0的容器,例如Tomcat 7,Glassfish 3,JBoss AS 6,并确保声明符合您的 web.xml 符合Servlet 3.0 spec,以便您可以执行以下操作:

The support for passing method arguments and invoking non-getter methods was introduced in EL 2.2 which is part of Servlet 3.0. So your best bet is to upgrade to a Servlet 3.0 compatible container, such as Tomcat 7, Glassfish 3, JBoss AS 6 and ensure that your web.xml is declared conform Servlet 3.0 spec, so that you can do the following:

<c:forEach var="entrant" items="${bean.entrants}">
    <tr>
        <td>${entrant.idEntrant}</td>
        <td>${bean.getGroupCode(entrant.idGroup)}</td>
        <td>${entrant.name}</td>
    </tr>
</c:forEach>

如果您的容器不支持它,那么您最好的选择是创建自定义EL功能。

If your container doesn't support it, then your best bet is to create a custom EL function.

        <td>${some:getGroupCode(bean, entrant.idGroup)}</td>

这篇关于EL方法中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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