问题与H:形式和p:阿贾克斯(Mojarra 2.0.2和2.0.2 Primefaces) [英] Problem with h:form and p:ajax (Mojarra 2.0.2 and Primefaces 2.0.2)

查看:129
本文介绍了问题与H:形式和p:阿贾克斯(Mojarra 2.0.2和2.0.2 Primefaces)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个网站:

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

< HTML的xmlns =htt​​p://www.w3.org/1999/xhtml
    的xmlns:UI =htt​​p://java.sun.com/jsf/facelets
    的xmlns:H =htt​​p://java.sun.com/jsf/html
    的xmlns:F =htt​​p://java.sun.com/jsf/core
    的xmlns:P =htt​​p://primefaces.prime.com.tr/ui>

< H:头>< / H:头>
< H:身体GT;


    < H:格式ID =形式,一些>
        &所述; H:的inputText的id =copingFilePhaseFocus>
            <电话号码:AJAX事件=焦点访谈的ActionListener =#{installationController.startCopyingWarFile}/>
        < /小时:inputText的>
    < /小时:形式GT;


< / H:身体GT;
< / HTML>
 

和后台bean:

  @ManagedBean(NAME =installationController)
@SessionScoped
公共类InstallationController实现IPluginInstallationListener {

    //这里的一些方法(...)

    公共无效startCopyingWarFile(ActionEvent的事件){
        的System.out.println(\ñ\ñ\ñ\ nStarted \ñ\ñ\ñ\ N);
    }
}
 

这code下的MyFaces 2.0.0工作。但在MyFaces的2.0.2或2.0.2 Mojarra没有。 通过告诉不工作我的意思是单击(聚焦)输入文本不触发的ActionListener(文字入门并没有出现在标准输出)。 有没有人同样的问题?

EDIT 1(更改P后:阿贾克斯到f:阿贾克斯):

 <电话号码:outputPanel ID =copingFilePhase>
        <电话号码:accordionPanel速度=0.2
            渲染=#{pluginInstallerWebBean.copingFilePhase}>
            <电话号码:标签
                标题=#{味精['installPlugin.copyingWar']} ...#{pluginInstallerWebBean.copingFilePhaseState}>
                < H:形式prependId =假>
                    <电话号码:重点=copingFilePhaseFocus/>
                    &所述; H:的inputText的id =copingFilePhaseFocus
                        渲染=#{pluginInstallerWebBean.copingFilePhaseFocus}
                        风格=显示:无;>
                        < F:Ajax事件=焦点
                            渲染=copingFilePhase obtainingPluginInformationPhase
                            听众=#{installationController.startCopyingWarFile}/>
                    < /小时:inputText的>
                < /小时:形式GT;
                #{味精['installPlugin.copyingWarDescription']}
            < / P:标签>
        < / P:accordionPanel>
    < / P:outputPanel>

    <电话号码:outputPanel ID =obtainingPluginInformationPhase>(...)< / P:outputPanel>
 

和错误是:

  

javax.faces.FacesException:   包含未知的ID   copingFilePhase - 无法找到它   在组件的上下文中   copingFilePhaseFocus

解决方案

这可能有两个原因:

  1. 在Primefaces资源的servlet配置不正确,这将导致必要的JavaScript代码就不会被加载。你应该能够在对焦输入检查JS错误控制台在你的网页浏览器的任何JS错误,才能看到它。在Firefox中,控制台可以通过pressing <大骨节病>控制 + <大骨节病>移 + <大骨节病>Ĵ

    该资源的servlet将在3.0的Servlet环境(Glassfish的第三版,Tomcat 7的,JBoss的6等)自动加载,但是,在旧的环境中,你需要手工在配置的web.xml

     &LT;的servlet&GT;
        &LT; servlet的名称&gt; PrimeFaces资源的Servlet&LT; / Servlet的名称&gt;
        &LT;的servlet类&GT; org.primefaces.resource.ResourceServlet&LT; / Servlet的类&GT;
    &LT; / servlet的&GT;
    &LT; Servlet映射&GT;
        &LT; servlet的名称&gt; PrimeFaces资源的Servlet&LT; / Servlet的名称&gt;
        &LT; URL模式&GT; / primefaces_resource / *&LT; / URL模式&GT;
    &LT; / Servlet映射&GT;
     

  2. 方法签名是错误的。你应该能够看到它通过读取服务器日志和日志中看到 javax.el.MethodNotFoundException 。在你的问题中code的例子是正确的,但有歧义的ActionEvent 。还有一类具有相同的名称在的java.awt.event 包。你可能有意外(自动)进口的。验证是否确实是 javax.faces.event.ActionEvent ,而不是别的东西。

如果没有帮助,您可能要考虑更换PrimeFaces 号码:AJAX 的标准JSF 2.0 F:AJAX

 &LT; F:Ajax事件=焦点监听器=#{installationController.startCopyingWarFile}/&GT;
 

 公共无效startCopyingWarFile(AjaxBehaviorEvent事件){
    // ...
}
 

其中, AjaxBehaviorEvent javax.faces.event.AjaxBehaviorEvent

I have got this site:

<!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>

And backing bean:

@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");
    }
}

This code was working under MyFaces 2.0.0. But under MyFaces 2.0.2 or Mojarra 2.0.2 does not. By telling "does not work" I mean that clicking (focusing) input text does not triggering actionListener (Text "Started" does not appear on standard output). Has anybody similar problem ?

EDIT 1 (After changing p:ajax to 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>

And the error is:

javax.faces.FacesException: contains an unknown id 'copingFilePhase' - cannot locate it in the context of the component copingFilePhaseFocus

解决方案

This can have two causes:

  1. The Primefaces resource servlet is not properly configured which will cause that the necessary JavaScripts won't be loaded. You should be able to see it by checking the JS error console in your webbrowser for any JS errors when focusing the input. In Firefox, the console is available by pressing Ctrl+Shift+J.

    The resource servlet will be loaded automatically in Servlet 3.0 environments (Glassfish v3, Tomcat 7, JBoss 6, etc), however in older environments, you need to configure it manually 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>
    

  2. The method signature is wrong. You should be able to see it by reading the server logs and seeing a javax.el.MethodNotFoundException in the logs. The code example in your question is correct, but there's ambiguity in ActionEvent. There's a class with the same name in java.awt.event package. You might have accidently (auto-)imported it. Verify if it is indeed javax.faces.event.ActionEvent and not something else.

If none helps, you may want to consider to replace the PrimeFaces p:ajax by the standard JSF 2.0 f:ajax:

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

with

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

where AjaxBehaviorEvent is javax.faces.event.AjaxBehaviorEvent.

这篇关于问题与H:形式和p:阿贾克斯(Mojarra 2.0.2和2.0.2 Primefaces)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆