gpt4 book ai didi

jsf - 为什么复合组件中某个方面内的 commandLink 会呈现错误?

转载 作者:行者123 更新时间:2023-12-04 21:38:48 25 4
gpt4 key购买 nike

当我创建一个包含分面的复合组件并在该分面内放置一个命令链接时,我收到一条错误消息:This link is disabled as it is not nested within a JSF form.
命令按钮的行为方式不同,所以我倾向于这是一个错误。

索引.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 :
<?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>

这是我的浏览器所做的:

enter image description here

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

最佳答案

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

组件.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 在两种情况下都不同:
  • 第一个帖子 --> 没有表单 ID 的 clientId
  • 我的帖子 --> clientId 包括表单 ID

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

    使用 Mojarra 2.2.13 (Primefaces 6.x)。

    关于jsf - 为什么复合组件中某个方面内的 commandLink 会呈现错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31996021/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com