当我创建一个带有facet的复合组件并在该facet中放置一个命令链接时,我收到一条错误消息:This link is disabled as it is not nested within a JSF form.
commandButton的行为方式不同,所以我倾向于这是一个bug。
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/没有comp/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>
这是我的浏览器制作的:
关于我可能做错了什么或者这确实是Mojarra 2.2.7中的错误的任何想法? (与NetBeans 8.0.2捆绑在一起)
一个旧的线程,但我认为当前的行为是一个错误,因为以下工作,所以它应该在复合组件中工作:
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在两种情况下都有所不同:
在我看来,这似乎是一个错误,但也许有人可以说服我,它不是; D
使用Mojarra 2.2.13(Primefaces 6.x)。