为什么复合组件内构面内的commandLink会出现错误? [英] Why does a commandLink within a facet within a composite component renders an error?

查看:58
本文介绍了为什么复合组件内构面内的commandLink会出现错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我创建一个包含构面的复合组件并将命令链接放置在该构面中时,会出现错误消息:此链接被禁用,因为它没有嵌套在JSF表单中.

When I create a composite component with a facet in it and place a command link within that facet, I get an error message: This link is disabled as it is not nested within a JSF form.

commandButton的行为方式不同,所以我倾向于这是一个错误.

A commandButton does not behave in the same way, so I am inclined to this this is a bug.

index.xhtml:

index.xhtml :

<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://xmlns.jcp.org/jsf/html"
      xmlns:mycomp="http://xmlns.jcp.org/jsf/composite/mycomp"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head>
    </h:head>
    <h:body>
        <mycomp:component>
            <f:facet name="someFacet">
                <h:commandLink value="this link should work, but does not (within form, within facet)"/><br/>
                <h:commandButton value="this button works as expected (within form, within facet)"/><br/>
            </f:facet>
        </mycomp:component>
    </h:body>
</html>

/resources/mycomp/component.xhtml:

/resources/mycomp/component.xhtml :

<?xml version='1.0' encoding='UTF-8' ?>
<ui:component
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:cc="http://xmlns.jcp.org/jsf/composite"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:a="http://xmlns.jcp.org/jsf/passthrough"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
    >
    <cc:interface>
        <cc:facet name="someFacet" required="true"/>
    </cc:interface>
    <cc:implementation>
        <h:commandLink value="this link should not work (not in a form)"/><br/>
        <h:form>
            <h:commandLink value="this link works as expected (within form, but not in facet)"/><br/>
            <cc:renderFacet name="someFacet"/>
        </h:form>
    </cc:implementation>
</ui:component>

这是我的浏览器所做的:

This is what my browser makes of it:

关于我可能做错了什么的任何想法,或者这确实是Mojarra 2.2.7中的错误?(与NetBeans 8.0.2捆绑在一起)

Any ideas as to what I may be doing wrong or is this indeed a bug in Mojarra 2.2.7? (which came bundled with NetBeans 8.0.2)

推荐答案

一个旧线程,但我认为当前行为是一个错误,因为以下工作有效,因此它应该在复合组件中工作:

an old thread but i think the current behaviour is a bug, because the following works, and so it should work in a composite component:

component.xhtml:

<?xml version='1.0' encoding='UTF-8' ?>
<ui:component
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:cc="http://xmlns.jcp.org/jsf/composite"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:a="http://xmlns.jcp.org/jsf/passthrough"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
>
<cc:interface>
    <cc:facet name="someFacet" required="true"/>
</cc:interface>
<cc:implementation>
    <h:commandLink value="this link should not work (not in a form)"/><br/>
        <h:commandLink value="this link works as expected (within form, but not in facet)"/><br/>
        <cc:renderFacet name="someFacet"/>
</cc:implementation>
</ui:component>

使用它( index.xhtml ):

<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://xmlns.jcp.org/jsf/html"
      xmlns:mycomp="http://xmlns.jcp.org/jsf/composite/mycomp"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head>
    </h:head>
    <h:body>
     <h:form>
        <mycomp:component>
            <f:facet name="someFacet">
                <h:commandLink value="this link should work, but does not (within form, within facet)"/><br/>
                <h:commandButton value="this button works as expected (within form, within facet)"/><br/>
            </f:facet>
        </mycomp:component>
      </h:form>
    </h:body>
</html>

在两种情况下,生成的HTML输出也都在组件树的正确位置(在表单下方)生成按钮.但是为按钮生成的clientId在两种情况下都不同:

Also the generated HTML output in both cases generates the button in the right place in the component tree (under the form). But the clientId generated for the button, differs in both cases:

  • 第一条帖子->没有表单ID的clientId
  • 我的帖子-> clientId包含表单ID

在我看来,这似乎是一个错误,但是也许有人可以说服我这不是一个错误; D

In my opinion this seems to be a bug, but perhaps someone can convince me that it is not ;D

使用Mojarra 2.2.13(Primefaces 6.x).

Using Mojarra 2.2.13 (Primefaces 6.x).

这篇关于为什么复合组件内构面内的commandLink会出现错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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