如何访问EL变量并将其作为参数传递给EL中的函数?

编程入门 行业动态 更新时间:2024-10-28 04:23:44
本文介绍了如何访问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 或 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中的函数?

本文发布于:2023-10-25 03:09:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1525747.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   函数   参数   并将其   EL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!