jsf - Referring composite component ID in f:ajax render -
i writing composite component intended wrap input element, , augment 'optional field' designation , h:message element below it. here component (in input.xhtml file):
<composite:interface/> <composite:implementation> <div> #{component.children[1].setstyleclass(component.children[1].valid ? '' : 'inputerror')} <composite:insertchildren/> </div> <h:panelgroup styleclass="optional" rendered="#{!component.parent.children[1].required}" layout="block" > #{msgs['common.optional.field']} </h:panelgroup> <h:message id="msgid" for="#{component.parent.children[1].id}" errorclass="error"/> </composite:implementation>
again, intended usage of component wrap h:input* element expected first , immediate child of in using page.
in using page write:
<h:form id="f1"> <h:panelgrid border="0" columns="2" style="width: 80%"> <f:facet name="header"> <col width="40%" /> <col width="60%" /> </f:facet> <h:outputlabel styleclass="sectionbody" for="i1" value="input 1"></h:outputlabel> <my:input id="ii1"> <h:inputtext id="i1" size="20" maxlength="20" tabindex="0" required="true" label="input 1"> </h:inputtext> </my:input> <h:outputlabel styleclass="sectionbody" for="i2" value="input 2"></h:outputlabel> <my:input id="ii2"> <h:inputtext id="i2" size="20" maxlength="20" tabindex="0" label="input 2"> </h:inputtext> </my:input> </h:panelgrid> <br /> <h:commandbutton value="submit" tabindex="1"> <f:ajax listener="#{terminalimportbean.addterminal}" execute="@form" render="@form"/> </h:commandbutton> </h:form>
this work fine using normal posts. if add add f:ajax validation "input 1" (id="i1") , try re-render composite (ii1) using following:
... <h:outputlabel styleclass="sectionbody" for="i1" value="input 1"></h:outputlabel> <my:input id="ii1"> <h:inputtext id="i1" size="20" maxlength="20" tabindex="0" required="true" label="input 1"> <f:ajax listener="#{mybean.checkinput1}" event="blur" render="ii1"/> </h:inputtext> </my:input> ...
i gen error in browser during ajax response processing:
malformedxml: during update: f1:ii1 not found
i tried using f1:ii1
, :f1:ii1
, no avail. when use msgid
or :f1:ii1:msgid
works. know why?
i using mojarra 2.1.3
thanks
that's because composite component itself not render html. children been rendered html. there not exist html element id f1:i11
in generated html output. open page in browser, rightclick , view source. in there yourself. there's no such element id. javascript/ajax encountering same problem. can't find element in order update it.
to solve this, you'd need wrap entire composite body in html <div>
or <span>
, assign id of #{cc.clientid}
prints uicomponent#getclientid()
.
<cc:implementation> <div id="#{cc.clientid}"> ... </div> </cc:implementation>
then can reference below:
<my:input id="foo" /> ... <f:ajax ... render="foo" />
you can reference specific composite component child.
<f:ajax ... render="foo:inputid" />
Comments
Post a Comment