Let's say: For repeatable code fragment reuse in different context. I had a fragment.xhtml will be included in multiple other different xhtml, say main1.xhtml and main2.xhtml
fragment.xhtml as:
<h:body>
<p:panelGrid id="qualifyGrid">
<f:facet name="header">
<p:row>
<p:column colspan="4">#{staffBean.currentStaff.name} Qualify</p:column>
</p:row>
</f:facet>
......
<p:row>
<p:column styleClass="addlabel"><h:outputLabel for="id" value="#{clientqualify['web.qualify.label.id']}"/></p:column>
<p:column styleClass="wideField" colspan="3">
<h:inputText id="id1" value="#{qualifyvalue1}" rendered=""/>
<h:inputText id="id" value="#{qualifyvalue}" rendered=""/>
</p:column>
</p:row>
......
<p:row>
<p:column styleClass="addlabel"><h:outputLabel for="name" value="#{clientqualify['web.qualify.label.name']}"/></p:column>
<p:column styleClass="wideField" colspan="3"><p:inputText styleClass="field" id="name" value="#{qualifyControlBean.currentQualify.qualifyName}" required="true"/></p:column>
</p:row>
</p:panelGrid>
</h:body>
main1.xhtml:
<h:body>
<ui:composition template="/WEB-INF/ozssc-staff-template.xhtml">
<ui:define name="content">
<h3>#{clientqualify['web.qualify.edit.heading']}</h3>
<p:messages id="messages" showDetail="true" autoUpdate="true" />
<h:form id="qualifyeditform" prependId="false">
<ui:include src="fragment.xhtml"/>
<h:panelGrid style="display:block" border="0">
<p:commandButton id="submit" value="Save" action="#{qualifyControlBean.saveQualify}" icon="fa fa-fw fa-save" ajax="false" disabled="#{qualifyControlBean.currentQualify.status=='Verified'}"/>
</h:panelGrid>
</h:form>
</ui:define>
</ui:composition>
</h:body>
main2.xhtml
<h:body>
<ui:composition template="/WEB-INF/ozssc-staff-template.xhtml">
<ui:define name="content">
<h3>#{clientqualify['web.qualify.edit.heading']}</h3>
<p:messages id="messages" showDetail="true" autoUpdate="true" />
<h:form id="qeditform" prependId="false">
<ui:include src="fragment.xhtml"/>
<h:panelGrid style="display:block" border="0">
<p:commandButton id="submit" value="Save" action="#{qualifyControlBean.saveQualify}" icon="fa fa-fw fa-save" ajax="false" disabled="#{qualifyControlBean.currentQualify.status=='Verified'}"/>
</h:panelGrid>
</h:form>
</ui:define>
</ui:composition>
</h:body>
from above snippets you saw, the fragment.xhtml was included into two different forms, in main1.xhtml, form id is "qualifyeditform" and in main2.xhtml, form id is "qeditform".
I am having difficult to find a way to let fragment.xhtml element rendering different input text by different parent context. i.e. if this fragment.xhtml was included into main1.xhtml (that in form id as: "qualifyeditform"), render inputText id "id1". If this fragment.xhtml was included into main2.xhtml (that in form id as: "qeditform") render inputText id "id".
How I can set The EL expression to find the parent form element's id? and use it in my rendered="" expression?
I think you can do
<h:inputText id="id1"
value="#{qualifyvalue1}"
rendered="#{component.parent.clientId eq 'qualifyeditform'}"/>