JSF 2.3组合件中ID错误的面

问题描述 投票:3回答:1

我在复合组件中具有以下简单代码(使用Mojarra 2.3.9 / Primefaces 7):

<composite:interface name="compForm" displayName="A composite form">
    <composite:facet name="actions" />
</composite:interface>

<composite:implementation>
    <h:form id="form">
            <composite:insertChildren />

            <ui:fragment rendered="#{!empty cc.facets.actions}">
                <div class="actions">
                    <composite:renderFacet name="actions" />
                </div>
            </ui:fragment>
        </div>
    </h:form>
</composite:implementation

然后在页面中使用以下部分,尝试用生命填充复合表单:

<cc:compForm id="mySpecialForm">

    ...

    <f:facet name="actions">
        <p:commandButton
                id="myBtn"
                value="Submit"
                process="@form"
                update="@form">
        </p:commandButton>
    </f:facet>
</cc:compForm>

表格和所有子项均正确呈现,并且运行良好。但是,我认为renderFacet块中的按钮具有错误的客户端ID,因为不是:

mySpecialForm:form:myBtn

该按钮仅获得以下clientId:

mySpecialForm:myBtn

这导致呈现页面时出错:

找不到从中引用的表达式“ @form”的组件“ mySpecialForm:myBtn” 。:org.primefaces.expression.ComponentNotFoundException:找不到从中引用的表达式“ @form”的组件“ mySpecialForm:myBtn”。

我是在做错什么,还是JSF / Primefaces中的错误?我还尝试将componentType配置为从UIForm扩展的@FacesComponent,但是在这种情况下,根本不会呈现任何形式。

jsf primefaces facet composite
1个回答
0
投票

我试图创建一个“最小的,可复制的示例(reprex)”,如Kukeltje所述。所有需要的只是Web应用程序中的那两个部分(两个文件都位于资源下):

cc / compForm.xhtml:

<html
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://xmlns.jcp.org/jsf/html"
        xmlns:composite="http://xmlns.jcp.org/jsf/composite">

    <composite:interface name="compForm" displayName="A composite form">
        <composite:facet name="actions" />
    </composite:interface>

    <composite:implementation>
        <h:form id="form">
            <composite:insertChildren />
            <composite:renderFacet name="actions" />
        </h:form>
    </composite:implementation>
</html>

compFormTest.xhtml:

<html
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://xmlns.jcp.org/jsf/html"
        xmlns:f="http://xmlns.jcp.org/jsf/core"
        xmlns:cc="http://xmlns.jcp.org/jsf/composite/cc">
    <cc:compForm id="mySpecialForm">
        <h:inputText id="inputParam" value="" />

        <f:facet name="actions">
            <h:commandButton id="myBtn" value="Test" />
        </f:facet>
    </cc:compForm>
</html>

所有待办事项都称为.xhtml页面:http:localhost / YOUR_APP / compFormTest.xhtml。

使用它之后(至少在Mojarra JSF实现中使用),输入字段具有以下正确的客户机ID mySpecialForm:form:inputParam。但是命令按钮检索了以下形式之外的另一个客户机ID:mySpecialForm:myBtn,从我的角度来看,这是关于JSF VDL的错误:“ ...此时将在复合组件VDL中呈现查看。”

但是当我对示例文件进行了精简处理时,这显然不是primefaces问题,因为如果使用标准的h:commandButton组件,则还会包含错误的客户端ID。

也许有人可以在MyFaces环境中使用上面提到的2个文件来检查行为是否不同或相同?

还是有人想办法解决?使用其他@FacesComponent并将按钮从构面移到表单下的正确位置会导致以下“有趣”重复ID错误:

“不能两次添加相同的组件:mySpecialForm:form:myBtn” (至少客户端ID是我最初期望的)

提前感谢

丹尼尔·K。

© www.soinside.com 2019 - 2024. All rights reserved.