如何访问EL变量并将其作为参数传递给EL中的函数? [英] how to access a EL variable and pass it as an argument to a function in EL?

查看:102
本文介绍了如何访问EL变量并将其作为参数传递给EL中的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在bean上调用函数,并使用EL在jsp中将参数传递给该函数。
问题是它不允许这样:
$ {teacherBean.certificationFor($ {particularField})

I want to call a function on a bean with an argument passsed to it in jsp using EL. The problem is it does not allow something like: "${teacherBean.certificationFor(${particularField})"

问题是我想遍历数组并为作为参数传递的数组中的所有值调用函数certificateFor。
我通过以下方式获取数组中的值:

the thing is i want to iterate over an array and call the function certificationFor for all the values in the array passed as an argument. I am getting the values in array by:

所以基本上我想做类似的事情:

$ {teacherBean.certificationFor($ {particularField})

但我不能这样做。
我可以通过其他任何方式吗?

So Basically i want to do something like: ${teacherBean.certificationFor(${particularField}) but i cant do that. can i do this in any other way?

我是EL的新手。 :)
感谢您的帮助。

I am a newbie in EL . :) Any help is appreciated.

推荐答案

您到底想在哪里做什么?只是为了获得展示价值?至少,在Java EE 6之前的标准EL中,您不能传递这样的方法参数。在 JBoss-EL 或< a href = http://java.sun.com/javaee/6/docs/tutorial/doc/gjddd.html rel = noreferrer> Java EE 6 EL 即可。语法就是:

Where exactly do you want to do that and for what? Just to get a value for display? At least, in standard EL prior to Java EE 6 you cannot pass method arguments like that. In JBoss-EL or in Java EE 6 EL you can do that. The syntax would then just have been:

${teacherBean.certificationFor(particularField)}

请注意,您不能嵌套EL表达式,EL表达式本身就是一个完整的表达式。

Note that you cannot nest EL expressions, an EL expression is already a whole expression at its own.

但是,在标准的EL实现中,您可以使用大括号符号通过键访问 Map 值。因此,例如,如果您有 Map< String,String>证书,其中的键对应于 particularField 以及与值关联的值:

In standard EL implementations you can however access Map values by keys using the brace notation. Thus, if you for example have a Map<String, String> certifications where the keys corresponds the particularField and the values the associated value:

private Map<String, String> certifications = new HashMap<String, String>();

public Map<String, String> getCertificationFor() {
    return this.certifications;
}

然后您可以使用以下表示法:

then you can use the following notation:

${teacherBean.certificationFor[particularField]}

这会在后台解决

teacherBean.getCertificationFor().get(particularField)

这篇关于如何访问EL变量并将其作为参数传递给EL中的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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