Why does commandLink inside a facet in a composite component generate an error?

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

The commandButton command does not behave like this, so I am prone to this, this is a mistake.

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:

 <?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 does:

enter image description here

Any ideas on what I might be doing wrong or is this really a bug in Mojarra 2.2.7? (which comes bundled with NetBeans 8.0.2)

+4
source share
1 answer

old thread, but I think the current behavior is a mistake, because the following works, and therefore it should work in the 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> 

Using it ( 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> 

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

  • First thread message -> clientId without form identifier
  • My post -> clientId includes form id

In my opinion, this seems like a mistake, but maybe someone can convince me that it is not: D

Using Mojarra 2.2.13 (Right 9).

0
source

All Articles