簡體   English   中英

h:form和p:ajax(Mojarra 2.0.2和Primefaces 2.0.2)的問題

[英]Problem with h:form and p:ajax (Mojarra 2.0.2 and Primefaces 2.0.2)

我有這個網站:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.prime.com.tr/ui">

<h:head></h:head>
<h:body>


    <h:form id="form-some">
        <h:inputText id="copingFilePhaseFocus">
            <p:ajax event="focus" actionListener="#{installationController.startCopyingWarFile}" />
        </h:inputText>
    </h:form>


</h:body>
</html>

和支持豆:

@ManagedBean(name = "installationController")
@SessionScoped
public class InstallationController implements IPluginInstallationListener {

    // Some methods here (...)

    public void startCopyingWarFile(ActionEvent event) {
        System.out.println("\n\n\n\nStarted\n\n\n\n");
    }
}

此代碼在MyFaces 2.0.0下運行。 但根據MyFaces 2.0.2或Mojarra 2.0.2沒有。 通過告訴“不起作用”我的意思是單擊(聚焦)輸入文本不會觸發actionListener(文本“已啟動”不會出現在標准輸出上)。 有沒有人有類似的問題?

編輯1(將p:ajax更改為f:ajax后):

    <p:outputPanel id="copingFilePhase">
        <p:accordionPanel speed="0.2"
            rendered="#{pluginInstallerWebBean.copingFilePhase}">
            <p:tab
                title="#{msg['installPlugin.copyingWar']} ... #{pluginInstallerWebBean.copingFilePhaseState}">
                <h:form prependId="false">
                    <p:focus for="copingFilePhaseFocus" />
                    <h:inputText id="copingFilePhaseFocus"
                        rendered="#{pluginInstallerWebBean.copingFilePhaseFocus}"
                        style="display:none;">
                        <f:ajax event="focus"
                            render="copingFilePhase obtainingPluginInformationPhase"
                            listener="#{installationController.startCopyingWarFile}" />
                    </h:inputText>
                </h:form>
                #{msg['installPlugin.copyingWarDescription']}
            </p:tab>
        </p:accordionPanel>
    </p:outputPanel>

    <p:outputPanel id="obtainingPluginInformationPhase">(...)</p:outputPanel>

錯誤是:

javax.faces.FacesException:包含一個未知的id'copingFilePhase' - 無法在組件copingFilePhaseFocus的上下文中找到它

這可能有兩個原因:

  1. Primefaces資源servlet未正確配置,這將導致不會加載必要的JavaScripts。 在聚焦輸入時,您應該能夠通過檢查webbrowser中的JS錯誤控制台來查看任何JS錯誤。 在Firefox中,按Ctrl + Shift + J即可使用控制台。

    資源servlet將自動加載到Servlet 3.0環境(Glassfish v3,Tomcat 7,JBoss 6等)中,但在舊環境中,您需要在web.xml手動配置它:

     <servlet> <servlet-name>PrimeFaces Resource Servlet</servlet-name> <servlet-class>org.primefaces.resource.ResourceServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>PrimeFaces Resource Servlet</servlet-name> <url-pattern>/primefaces_resource/*</url-pattern> </servlet-mapping> 
  2. 方法簽名是錯誤的。 您應該能夠通過閱讀服務器日志並在日志中看到javax.el.MethodNotFoundException來查看它。 您的問題中的代碼示例是正確的,但ActionEvent存在歧義。 java.awt.event包中有一個具有相同名稱的類。 您可能會意外(自動)導入它。 驗證它是否確實是javax.faces.event.ActionEvent而不是其他東西。

如果沒有幫助,您可能需要考慮用標准JSF 2.0 f:ajax替換PrimeFaces p:ajax f:ajax

<f:ajax event="focus" listener="#{installationController.startCopyingWarFile}" />

public void startCopyingWarFile(AjaxBehaviorEvent event) {
    // ...
}

其中AjaxBehaviorEventjavax.faces.event.AjaxBehaviorEvent

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM