java - 为什么这个 EL 表达式无效?

标签 java jsf el

我正在执行一个简单的注销,并希望确保我正确引用了登录根目录。

<h:form>
  <h:commandLink value="Logout" action="#{request.contextPath}/#{userController.logout()}" />
</h:form>

但我收到此错误:

/topnav.xhtml @16,104 action="#{request.contextPath}/#{userController.logout()}" Not a Valid Method Expression: #{request.contextPath}/#{userController.logout()}

更新

现在,我正在添加从注销链接到登录页面的导航规则,并且由于注销链接位于所有页面上,我需要添加规则以允许转换回登录页面。对于一个简单的项目来说,这似乎有很多配置。我宁愿只调用该方法来指示登录页面是最终目的地,并且必须放置从所有页面到登录页面的导航条目。

最佳答案

来自 commandLink 的文档:

Name      Required  Request-time    Type
==============================================================
action    false     false           javax.el.MethodExpression 

复合表达式#{request.contextPath}/#{userController.logout()}无法解析为 MethodExpression .

JSF 2.1 specification MethodExpressions 说:

Method expressions are a very similar to value expressions, but rather than supporting the dynamic retrieval and setting of properties, method expressions support the invocation (i.e. execution) of an arbitrary public method of an arbitrary object, passing a specified set of parameters, and returning the result from the called method (if any).

关于java - 为什么这个 EL 表达式无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11111701/

相关文章:

java - Android性能优化问题(Layout with JustifiedTextViews and CodeViews)

java - Ajax Facelets 支持的 "events"是什么?

ajax - JSF(Primefaces)通过ID对多个元素进行Ajax更新

java - 如何在 .jsp 中包含 JSTL/EL 页脚?

java - 如何正确设计具有内部条件转换的游戏状态机

java - 匹配以空格开头的所有行,直到不以空格开头的行

Java:为什么 Calendral.setTimeInMillis(0) 设置错误的时间

jsf - 如何确定代码中的当前 JSF 生命周期阶段

jsp - 如何在 EL 表达式语言 ${} 中访问对象

java - Java中如何以紧凑的方式指定复杂对象的字段值?