2013-02-26 40 views
0

我一直在摸索着這個問題......我有很多項目都有工作的commandLink元素,但是我不能爲我的生活得到它在這個項目中工作。我在這裏遵循BalusC的迴應:commandButton/commandLink/ajax action/listener method not invoked or input value not updated直到信,但仍然沒有喜悅。h:commandLink拒絕調用方法並隨機重定向到項目根

目前我煮我的代碼到簡單,因爲它可以去:

@ManagedBean 
@SessionScoped 
public class TestBean { 

    private @Inject transient Logger logger; 

    public void testEvent(ActionEvent actionEvent) { 
     logger.log(Level.INFO, "Event Fired!!"); 
     return; 
    } 
} 

在我的XHTML文件我有:

<h:form> 
    <h:commandLink id="test" actionListener="#{testBean.testEvent}" value="Test Me!"/> 
</h:form> 

當我點擊鏈接,方法是沒有被調用,我被重定向到web-apps根目錄(登錄頁面,儘管有一個登錄過濾器:/)如果我改變鏈接到一個commandButton它按預期工作。

當前應用程序利用ui:composition標籤進行模板化,並且我已經對嵌套的h:form標籤進行了三重檢查,我沒有使用任何ajax調用或額外的JS庫。我的模板實現了jsf標籤,它在哪裏很重要,即h:head,h:body等。任何人都可以提供任何跡象或可能的原因,我正在經歷的奇怪行爲?

最後,我已經在我的web-app中的各種頁面上測試了這個commandLink,並且commandLink元素通常拒絕調用。

這裏是我的鏈接的已編譯的HTML如果有人有興趣:

<form id="j_idt26" name="j_idt26" method="post" action="/my-project/webpages/Login.xhtml" enctype="application/x-www-form-urlencoded"> 
    <input type="hidden" name="j_idt26" value="j_idt26" /> 
    <a id="j_idt26:test" href="#" onclick="mojarra.jsfcljs(document.getElementById('j_idt26'),{'j_idt26:test':'j_idt26:test'},'');return false">Test Me!</a><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="-109553560791909389:-730254890454894147" autocomplete="off" /> 
</form> 
+0

它是否按照'actionListener'的順序使用'action'?嘗試從方法的簽名中刪除參數並將返回類型更改爲String。 – 2013-02-26 21:48:29

+0

是的,我試過這個,它會產生相同的結果。 – Ally 2013-02-26 21:51:52

+0

您提供的代碼示例按預期工作。你可以發表一個[SSCCE](http://sscce.org)你正在努力工作的代碼嗎? – 2013-02-26 21:52:56

回答

0

重建項目後,commandLinks工作,因爲他們應該和我無法重現錯誤在我的新項目。如果我有時間,我會嘗試調試我的原始項目並確定原始問題是/是。