在EL中嵌套变量 [英] Nesting variables in EL

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

问题描述

是否可以使用FacesContext或其他诸如requestsession等隐式对象在EL中嵌套下面的变量调用?这当然是行不通的.我收到此错误

Is it possible to nest variable calls like below in EL using FacesContext or other implicit objects like request, session, etc.? This of course is not working. I get this error

错误解析:#{myBean.myMethod(#{FacesContext.getCurrentInstance().getViewRoot().getViewId()})}

Error Parsing: #{myBean.myMethod(#{FacesContext.getCurrentInstance().getViewRoot().getViewId() })}

为此尝试

<ui:include src="#{myBean.myMethod(#{FacesContext.getCurrentInstance().getViewRoot().getViewId() })}">

推荐答案

这确实是无效的EL语法. #{}的嵌套是不允许的.只需将整个表达式放在相同的#{}中.另外,#{FacesContext}在Facelets的EL范围中不存在,它是#{facesContext},并且已经是当前实例.此外,如果已经是getter方法,则不必用括号指定整个方法名称.

This is indeed invalid EL syntax. Nesting of #{} is disallowed. Just put the whole expression inside the same #{}. Plus, the #{FacesContext} doesn't exist in Facelets' EL scope, it's #{facesContext} and it's already the current instance. Further, you don't necessarily need to specify the entire method name with parentheses if it are getter method already.

所以,这应该做

<ui:include src="#{myBean.myMethod(facesContext.viewRoot.viewId)}">

(请注意,这仍然需要具有Servlet 3.0/EL 2.2支持的目标容器)

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

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