我正在执行一个简单的注销,并希望确保我正确引用了登录根目录。
<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/