6

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?

Jason Wheeler
  • 872
  • 1
  • 9
  • 23
  • This may be helpful: http://illegalargumentexception.blogspot.com/2009/10/jsf-working-with-component-identifiers.html – BalusC Dec 12 '11 at 15:11
  • @BalusC, Thanks! that got me a lot closer – Jason Wheeler Dec 15 '11 at 00:43
  • hava you tried using javascript or jquery? – Philipp Sander Oct 25 '13 at 12:25
  • Yes, I ended up hand crafting javascript to solve the issue that lead me to search for "introspection" type stuff for JSF 1.2. Nonetheless, I am curious to know how things like that can be done. – daveloyall Oct 25 '13 at 14:38
  • @dave: With a custom taghandler. – BalusC Oct 25 '13 at 17:56
  • @BalusC, if you're confident that there is no JSF 1.2 equivalent to the JSF 2 `#{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 said `component` 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.) – daveloyall Oct 25 '13 at 19:21

0 Answers0