如何访问 EL 变量并将其作为参数传递给 EL 中的函数?
我想调用 bean 上的函数,并使用 EL 在 jsp 中传递给它的参数。 问题是它不允许这样的事情: “${teacherBean.certificationFor(${pspecialField})
”
的问题是我想迭代一个数组并为作为参数传递的数组中的所有值调用函数certificationFor。 我通过以下方式获取数组中的值:
所以基本上我想做一些类似的事情: ${teacherBean.certificationFor(${pspecialField}) 但我不能那样做。 我可以用其他方式做到这一点吗?
我是 EL 的新手。 :) 任何帮助表示赞赏。
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})
"
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:
So Basically i want to do something like:
${teacherBean.certificationFor(${particularField})
but i cant do that.
can i do this in any other way?
I am a newbie in EL . :)
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您到底想在哪里这样做以及为了什么?只是为了获取显示值?至少,在 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 你可以做到这一点。语法将是:
请注意,您不能嵌套 EL 表达式,EL 表达式本身已经是一个完整的表达式。
然而,在标准 EL 实现中,您可以使用大括号表示法通过键访问 Map 值。因此,如果您有一个
MapCertifications
其中键对应于preferredField
且值对应于关联值:那么您可以使用以下表示法:
这在幕后解析为
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:
Note that you cannot nest EL expressions, an EL expression is already a whole expression at its own.
In standard EL implementations you can however access
Map
values by keys using the brace notation. Thus, if you for example have aMap<String, String> certifications
where the keys corresponds theparticularField
and the values the associated value:then you can use the following notation:
this resolves behind the scenes to
我认为在标准 EL 中,除了定义封装在 EL 函数中的函数之外,您没有任何选择;
阅读: http://java.sun.com/j2ee/ 1.4/docs/tutorial/doc/JSPIntro7.html 靠近底部
文档;
但正如 BalusC 已经提到的,如果您有能力将这种依赖项添加到您的应用程序中,您是否可以使用其他 EL 实现
I think in the standard EL you don't have any options other than defining your functions wrapped in a EL function;
Read: http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPIntro7.html near the bottom of the
document;
but as BalusC mentioned already if you could use another EL implmentation if you have the ability to add that kind of dependency to your app
怎么样:
What about:
如果您要访问的通用功能更好地表达为单独的函数,则可以按如下方式编写:
其中 CertificationFor 映射到扩展 ELMethod.java 类。您可以在
result(Object[] args)
方法中实现该功能。此方法的参数是您传递给 EL 中的${certificationFor}
对象的参数。技巧是使用你的对象作为映射的链式映射,这是将多个参数传递给 EL 函数的一种方法。
如果您有兴趣,可以在此处查看完整代码和代码片段:
http://www.vineetmanohar.com /2010/07/如何在 el-methods 中传递参数/
If you are accessing a general functionality that is better expressed as a separate function, then you can write it as follows:
where certificationFor maps to the CertificationFor class which extends ELMethod.java class. You implement the functionality in the
result(Object[] args)
method. The args to this method are the args that you passed to the${certificationFor}
object in EL.The trick is to use your object as a chained map of maps, that is one way to pass multiple args to EL function.
If you are interested, you can see full code and code snippets here:
http://www.vineetmanohar.com/2010/07/how-to-pass-parameters-in-el-methods/