Goal:
The facelet outer.xhtml contains the composite component resources/components/foocomp.xhtml.
I want when I click the button in the foocomp.xhtml to update the form in order I see any errors/messages in <messages>
Attempt 1: using @form (not working)
Facelet outer.xhtml:
xmlns:comps="http://java.sun.com/jsf/composite/components">
<h:form>
<!-- PrimeFaces messages component; equivalent to <h:messages> -->
<p:messages showDetail="false" globalOnly="true"></p:messages>
<comps:foocomp></comps:foocomp>
</h:form>
<p:commandButton action="#{fooBean.myAction()}"
update="@form"></p:commandButton>
Output:
javax.faces.FacesException: Cannot find component with identifier "'id_j3'" in view.
* Note: the id id_j3 is the random id given to the form as I found out.
Attempt 2: giving the form an id (not working)
Facelet outer.xhtml:
xmlns:comps="http://java.sun.com/jsf/composite/components">
<h:form id="outerForm" prependId="false">
<!-- PrimeFaces messages component; equivalent to <h:messages> -->
<p:messages showDetail="false" globalOnly="true"></p:messages>
<comps:foocomp formId="outerForm"></comps:foocomp>
</h:form>
<composite:interface>
<!-- the enclosed form id which will updated after an action is triggered -->
<composite:attribute name="formId" type="java.lang.String" required="true" />
</composite:interface>
<p:commandButton action="#{fooBean.myAction()}"
update="#{cc.attrs.formId}">
</p:commandButton>
Output:
javax.faces.FacesException: Cannot find component with identifier "'outerForm'" in view.
Attempt 3: giving the form an id and referencing it with ':' (working!)
Facelet outer.xhtml:
xmlns:comps="http://java.sun.com/jsf/composite/components">
<h:form id="outerForm" prependId="false">
<!-- PrimeFaces messages component; equivalent to <h:messages> -->
<p:messages showDetail="false" globalOnly="true"></p:messages>
<comps:foocomp formId="outerForm"></comps:foocomp>
</h:form>
<composite:interface>
<!-- the enclosed form id which will updated after an action is triggered -->
<composite:attribute name="formId" type="java.lang.String" required="true" />
</composite:interface>
<p:commandButton action="#{fooBean.myAction()}"
update=":#{cc.attrs.formId}"></p:commandButton>
Thank you for posting this, you just saved my day! :)
ReplyDeleteYour welcome. Its always nice getting feedback ;) I wish I had more time posting more snippsets of code ...
ReplyDelete