Primefaces嵌套对话框/'appendToBody'-不触发Bean操作 [英] Primefaces nested Dialogs / 'appendToBody' - backing bean action not firing

查看:87
本文介绍了Primefaces嵌套对话框/'appendToBody'-不触发Bean操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在两个不会触发的嵌套表单中有一个支持bean方法(会话范围).

I have a backing bean method (session scoped) within two nested forms which will not fire.

我用一个展示问题的通用示例列出了问题.

I set out the question with a generic example which exhibits the problem.

对于了解表单,对话框和appendToBody标记是如何/为什么引起问题的理解,我将不胜感激.

I would appreciate an insight into how/why the forms, dialogs and appendToBody tag are causing the problem.

为澄清起见,contentsOfDialogTwo.xhtml-nestedDialogsBean.actionOnClickOfDialogTwoItem()-中的动作不会触发.显示了javascript警报,但是在后备Bean上的操作的断点显示未调用它.

To clarify, the action in contentsOfDialogTwo.xhtml - nestedDialogsBean.actionOnClickOfDialogTwoItem() - does not fire. The javascript alert is displayed, but a breakpoint on the action on the backing bean shows that this is not called.

模板视图:

<!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:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">
<ui:composition>
    <ui:insert name="content"/>
</ui:composition>
</html>

父视图:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
<ui:composition template="../templates/layout.xhtml">
    <ui:define name="content">
        <h:form>
            <p:panel>
                <p:tabView id="exampleTabView" dynamic="false">
                    <p:tab id="nestedDialogsTab" title="Nested Dialogs Tab">
                        <ui:insert>
                            <ui:include src="childView.xhtml"></ui:include>
                        </ui:insert>
                    </p:tab>
               </p:tabView>
            </p:panel>
         </h:form>
    </ui:define>
</ui:composition>
</html>

子视图:

<!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:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:p="http://primefaces.org/ui">
    <ui:composition>
    <p:commandButton 
    id="openDialog1" 
    value="Open Dialog 1"
    action="#{nestedDialogsBean.actionOnOpenOfDialog1()}"
    oncomplete="dialogOneVar.show()">
     </p:commandButton>
    <p:dialog id="dialogOne" header="Panel One" widgetVar="dialogOneVar"
            resizable="false" modal="true" closable="true" dynamic="true"
            hideEffect="fold" draggable="false" height="700" width="1000">
            <ui:insert>
                <ui:include src="contentsOfDialogOne.xhtml"></ui:include>
            </ui:insert>
        </p:dialog>
    </ui:composition>
    </html>

contentsOfDialogOne.xhtml:

<!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:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
    <p:commandButton 
    id="openDialog2" 
    value="Open Dialog 2"
    action="#{nestedDialogsBean.actionOnOpenOfDialog2()}"
    oncomplete="dialogTwoVar.show()">
     </p:commandButton>
    <p:dialog id="dialogTwo"
        header="Dialog Two"
        widgetVar="dialogTwoVar" 
        closable="true"
        dynamic="true" 
            resizable="false" draggable="false" height="700"
        width="1000" hideEffect="fold" appendToBody="true" >
        <ui:insert>
            <ui:include src="contentsOfDialogTwo.xhtml"></ui:include>
        </ui:insert>
    </p:dialog>
</ui:composition>
</html>

contentsOfDialogTwo.xhtml

<!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:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
<ui:composition>
    <h:form id="innerWrapperFormForDialogTwoDueToAppendToBody">
         <p:commandButton id="actionInsideDialogTwouButton"
         action="#{nestedDialogsBean.actionOnClickOfDialogTwoItem()}"
                onclick="alert('Button clicked')"
                value="Invoke Backing Bean Action">
            </p:commandButton>
</h:form>
</ui:composition>
</html>

推荐答案

从不使用嵌套表单

appendToBody:将对话框附加为文档主体的子代.

appendToBody : Appends dialog as a child of document body.

使用它时,对话框的渲染内容将附加到主体上,因此,例如,如果在xhtml中对话框是由h:form包装的,而您在生成的页面中使用appendToBody="true",则对话框将不会被包装form标记

When using it the rendered content of the dialog is being appended to the body , so if for example in your xhtml the dialog was wrapped by h:form and you using appendToBody="true" in the generated page the dialog wont be wrapped by the form tag

这在HTML中是非法的,其行为是不确定的,并取决于所使用的Web浏览器. Ajax链接不提交表单,它只是通过JavaScript收集输入值,然后在后台发送XMLHttpRequest. 为什么a:commandLink的action属性起作用,而h:commandLink的no属性起作用?

This is illegal in HTML and the behaviour is unspecified and dependent on the webbrowser used. The ajax link doesn't submit the form, it just collects the input values by JavaScript and then sends a XMLHttpRequest in the background. why a:commandLink's action attribute works but h:commandLink's does not?

JSF页面中的多个h:form

这篇关于Primefaces嵌套对话框/'appendToBody'-不触发Bean操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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