質問

私はこのサイトを持っています:

<!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のコンテキストでそれを見つけることができません

役に立ちましたか?

解決

これには2つの原因があります。

  1. PrimeFacesリソースサーブレットは適切に構成されていないため、必要なJavaScriptがロードされないようになります。入力に焦点を合わせるときに、JSエラーがJSエラーのJSエラーコンソールをチェックすることで、それを見ることができるはずです。 Firefoxでは、コンソールを押すことで利用できます Ctrl+シフト+j.

    リソースサーブレットは、サーブレット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 そして、他のものではありません。

何も役に立たない場合は、PrimeFacesを交換することを検討することをお勧めします p:ajax 標準JSF 2.0によって f:ajax:

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

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

どこ AjaxBehaviorEventjavax.faces.event.AjaxBehaviorEvent.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top