Problema con h: forma e p: Ajax (Mojarra 2.0.2 e 2.0.2 primefaces)
-
08-10-2019 - |
Domanda
Ho ottenuto questo sito:
<!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>
E supporto di fagioli:
@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");
}
}
Questo codice è stato lavorando sotto MyFaces 2.0.0. Ma sotto MyFaces 2.0.2 o 2.0.2 Mojarra non lo fa. Dicendo "non funziona" Voglio dire che il testo di input, facendo clic (messa a fuoco) non innescare ActionListener (Testo "Avviato" non appare sullo standard output). Qualcuno ha problema simile?
EDIT 1 (p Dopo aver cambiato: ajax af: 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>
E l'errore è:
javax.faces.FacesException: contiene un ID sconosciuto 'CopingFilePhase' - non può individuarlo nel contesto del componente copingFilePhaseFocus
Soluzione
Questo può avere due cause:
-
La risorsa servlet primefaces non è configurato correttamente che farà sì che i JavaScript necessari non verranno caricati. Dovreste essere in grado di vederlo verificando la console errore di JS nel vostro browser per eventuali errori JS quando concentrandosi l'ingresso. In Firefox, la console è disponibile premendo Ctrl + Maiusc + J .
Il servlet risorsa verrà caricato automaticamente nella Servlet 3.0 ambienti (v3 Glassfish, Tomcat 7, JBoss 6, ecc), ma in ambienti più grandi, è necessario configurare manualmente in
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>
-
La firma di metodo è sbagliato. Si dovrebbe essere in grado di vedere leggendo i log del server e vedendo un
javax.el.MethodNotFoundException
nei registri. L'esempio di codice nella tua domanda è corretta, ma non c'è ambiguità nellaActionEvent
. C'è una classe con lo stesso nome in packagejava.awt.event
. Si potrebbe avere accidentalmente (auto-) importato. Verificare se è davverojavax.faces.event.ActionEvent
e non qualcos'altro.
Se nessuno aiuta, si può prendere in considerazione per sostituire la p:ajax
primefaces dal JSF 2.0 f:ajax
di serie:
<f:ajax event="focus" listener="#{installationController.startCopyingWarFile}" />
con
public void startCopyingWarFile(AjaxBehaviorEvent event) {
// ...
}
dove AjaxBehaviorEvent
è javax.faces.event.AjaxBehaviorEvent
.