I am writing a Facelet tag file in JSF 1.2. I want to be able to reference the parent container. In JSF 2.0 I could make this a composite component and use #{cc.parent}
. But is there a JSF 1.2-equivalent way of doing this?
taglib.xml
<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN" "facelet-taglib_1_0.dtd">
<facelet-taglib>
<namespace>http://company.com/jsf</namespace>
<tag>
<tag-name>parentid</tag-name>
<source>../components/parentid.xhtml</source>
</tag>
</facelet-taglib>
parentid.xhtml
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.org/rich"
xmlns:ui="http://java.sun.com/jsf/facelets">
<!-- The next line is the line that isn't working for me -->
<h:outputText binding="#{obj}" value="Parent id is: #{obj.parent.id}" />
</ui:composition>
testpage.xhtml
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.org/rich"
xmlns:test="http://company.com/jsf"
xmlns:ui="http://java.sun.com/jsf/facelets">
...
<a:form id="form1">
<test:parentid />
</a:form>
<a:form id="form2">
<test:parentid />
</a:form>
...
</ui:composition>
I edited this to include the information from BalusC's link, and I'm almost there.
In the example, it works perfectly if there is just form1. But adding form2, this is the output I get:
Parent id is: form2
Parent id is: form2
What I want is:
Parent id is: form1
Parent id is: form2
So the binding in the composition is getting overwritten with whatever the last binding is. I tried to use a map and bind to that, but that didn't work. How could I solve this?
#{component}
object, then post that as an answer and I'll accept it as true. I mean, it is what it is, right? :) (Note, I'm presuming that saidcomponent
object would have a reference to the parent component and thus be a workable solution to this question, which wasn't asked by me but is in the ballpark.) – Octillion