How to access parent component from Facelet tag file in JSF 1.2
Asked Answered
G

0

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?

Garman answered 8/12, 2011 at 1:10 Comment(6)
This may be helpful: illegalargumentexception.blogspot.com/2009/10/…Beslobber
@BalusC, Thanks! that got me a lot closerGarman
hava you tried using javascript or jquery?Sorehead
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.Octillion
@dave: With a custom taghandler.Beslobber
@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.)Octillion

© 2022 - 2024 — McMap. All rights reserved.