Java JSF 2.0-使用AJAX动态加载时未调用Primefaces ActionListenser

Java JSF 2.0-使用AJAX动态加载时未调用Primefaces ActionListenser,java,jsf-2,primefaces,Java,Jsf 2,Primefaces,我正在使用JSF 2.0和Primefaces 3.2开发应用程序,遇到以下问题: 如果使用ajax请求动态加载内容,则不会调用ActionListeners 主要布局: <div id="content"> <h:form name="content_form" id="content_form"> <ui:insert name="content" /> </h:form> </div> 单击菜单项

我正在使用JSF 2.0和Primefaces 3.2开发应用程序,遇到以下问题: 如果使用ajax请求动态加载内容,则不会调用ActionListeners

主要布局:

<div id="content">
    <h:form name="content_form" id="content_form">
        <ui:insert name="content" />
    </h:form>
</div>
单击菜单项后,它调用AjaxViewBean“请求范围”,以设置当前视图页面并更新主布局中的“内容表单”

包含的页面(其中操作侦听器不工作)

  • 第一次尝试-文件上载(uploadFile.xhtml)

    
    
    永远不会调用fileUploadController。 如果我直接请求uploadfile.xhtml,或者在第一次加载时包含它,那么我可以上载该文件,这样我就可以确保上载是工作文件,并且在web.xml中正确配置了所有内容

  • 第二次尝试-包含页面中的菜单操作侦听器

    <h:body>
    <h:form>
        <p:menu type="tiered" style="width:180px">
            <p:submenu label="Ajax Menuitems" icon="ui-icon-refresh">
                <p:menuitem value="Save"
                    actionListener="#{ajaxViewBean.setViewName()}" update="messages"
                    icon="ui-icon-disk" />
                <p:menuitem value="Update" actionListener="#{buttonBean.update}"
                    update="messages" icon="ui-icon-arrowrefresh-1-w" />
            </p:submenu>
        </p:menu>
    </h:form>
    
    
    
    此外,尽管在主页面中使用的事件监听器是根据上述代码动态生成的,但该事件监听器从不触发

Maven依赖项:

<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-api</artifactId>
    <version>2.1.4</version>
</dependency>
<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-impl</artifactId>
    <version>2.1.4</version>
</dependency>
<dependency>
    <groupId>javax.servlet.jsp.jstl</groupId>
    <artifactId>jstl-api</artifactId>
    <version>1.2</version>
</dependency>
<dependency>
    <groupId>com.sun.facelets</groupId>
    <artifactId>jsf-facelets</artifactId>
    <version>1.1.14</version>
</dependency>
<dependency>
    <groupId>javax.el</groupId>
    <artifactId>el-api</artifactId>
    <version>2.2</version>
</dependency>
<dependency>
    <groupId>org.glassfish.web</groupId>
    <artifactId>el-impl</artifactId>
    <version>2.2</version>
</dependency>
<dependency>
    <groupId>org.primefaces</groupId>
    <artifactId>primefaces</artifactId>
    <version>3.2</version>
</dependency>
<dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.2.2</version>
</dependency>
<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.3</version>
</dependency>  

com.sun.faces
JSFAPI
2.1.4
com.sun.faces
jsf impl
2.1.4
javax.servlet.jsp.jstl
JSTLAPI
1.2
com.sun.facelets
jsf facelets
1.1.14
javax.el
埃尔api
2.2
org.glassfish.web
厄尔尼普勒
2.2
org.primefaces
素面
3.2
文件上传
文件上传
1.2.2
公地io
公地io
2.3
如果我遗漏了什么,有人能给我一些建议吗?或者我该如何解决这个问题


事实上,这是我在Stackoverflow上的第一篇文章,所以我希望我说得很清楚,格式没有弄乱,因为我可以看到你正在嵌套表单。这在HTML/XHTML中是不允许的

您有封闭的
内容\u表单
,包含页面也有各自的表单

尝试删除
内容\u表单

<div id="content">
    <ui:insert name="content" />
</div>

希望有帮助。

已修复!,我正在发布答案(可能对某人有用) 步骤如下:

        FacesContext context = FacesContext.getCurrentInstance();
        MethodExpression methodExpression = context
                .getApplication()
                .getExpressionFactory()
                .createMethodExpression(
                        context.getELContext(),
                        "#{ajaxViewBean.setViewName('" + navItem.getUrl()
                                + "')}", null,
                        new Class[] { ActionEvent.class });
        displayMenuItem.setUpdate(":content_form");
        displayMenuItem
                .addActionListener(new MethodExpressionActionListener(
                        methodExpression));
  • 确保没有违反此URL:
  • 根据此URL将部分状态保存方法使用为false:

    
    javax.faces.PARTIAL_STATE_保存
    假的
    
需要强调的是:

  • 但是,全局禁用部分状态保存的缺点是视图状态大小将增大。因此,如果使用服务器端状态保存方法,则服务器的内存使用量将增加;如果使用客户端状态保存方法,则网络带宽使用量将增加。基本上,您可以获得与JSF1.x中相同的视图状态信息。如果可能,您也可以通过web.xml中的以下上下文参数禁用每个视图的部分状态保存

非常感谢您回答我的问题,我确实在示例中嵌套了表单,我已经在代码中修复了这个问题,但没有工作。我遵循以下URL:并确保这些规则中没有违反任何内容。关于提供的解决方案,我应用了它,并收到了“无法找到标识符为的组件”:视图中的内容。在我的新代码中,我确保它没有嵌套表单,因此我将其放在包含页面之前的索引页面中,而它没有呈现
<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-api</artifactId>
    <version>2.1.4</version>
</dependency>
<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-impl</artifactId>
    <version>2.1.4</version>
</dependency>
<dependency>
    <groupId>javax.servlet.jsp.jstl</groupId>
    <artifactId>jstl-api</artifactId>
    <version>1.2</version>
</dependency>
<dependency>
    <groupId>com.sun.facelets</groupId>
    <artifactId>jsf-facelets</artifactId>
    <version>1.1.14</version>
</dependency>
<dependency>
    <groupId>javax.el</groupId>
    <artifactId>el-api</artifactId>
    <version>2.2</version>
</dependency>
<dependency>
    <groupId>org.glassfish.web</groupId>
    <artifactId>el-impl</artifactId>
    <version>2.2</version>
</dependency>
<dependency>
    <groupId>org.primefaces</groupId>
    <artifactId>primefaces</artifactId>
    <version>3.2</version>
</dependency>
<dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.2.2</version>
</dependency>
<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.3</version>
</dependency>  
<div id="content">
    <ui:insert name="content" />
</div>
displayMenuItem.setUpdate(":content");
<context-param>
  <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
  <param-value>false</param-value>
</context-param>