2012-06-20 24 views
0

我正在做一個簡單的註銷,並希望確保我正確地引用到登錄根。爲什麼這是無效的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()} 

UPDATE

現在,我從退出鏈接到登錄頁面,並自注銷鏈接添加導航規則是在所有頁面我需要添加規則以允許轉換回登錄頁面。這似乎是一個簡單的項目很多配置。寧願只是調用方法表示登錄頁面最終目標和熱點必須將所有頁面的導航條目放置到登錄頁面。

+1

你並不需要做的是,該方法已經表達確保正確的方法被調用。 –

+0

我希望我可以使用這種技術來控制導航。 – simgineer

回答

1

嘗試

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

的事實,你不需要背景下身邊,你不能使用#兩次,你正在使用它的方式。

+1

修復代碼不是一個好的答案。如果你能解釋爲什麼你應該改變,那將是很棒的。 –

+1

@LuiggiMendoza我會認爲這條線_beside事實上,你不需要上下文,你不能使用#兩次你使用它的方式._會照顧這個反對意見:) – Shahzeb

5

從文檔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).