Setting id's for the datatables.

I have a datatable "A" in which another datatable "B" is nested. I need to hide/unhide "B" from the onclick event of an item on the datatable "A". But i can't seem to set the id of the datatable "B". How can i achieve this?
[231 byte] By [AshishShakyaa] at [2007-11-27 2:56:37]
# 1
> But i can't seem to set the id of the datatable "B".Why not? Just set the ID in <h:dataTable id="setTheIdHere">.
BalusCa at 2007-7-12 3:34:30 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
I had run into a similar problem some time back. I was not able to have more than one nested dataTable inside <t:dataTable.../>Do you mean that?
jesefa at 2007-7-12 3:34:30 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Ops, sorry for two posts...

if you mean that :-)

do this:

<t:dataTable id="containingTable" rowIndexVar="rowIndex" ....>

...

<t:dataTable id="childTable"

forceId="true"

forceIdIndexFormula="#{rowIndex}" ... >.

..

</t:dataTable>

</t:dataTable>

jesefa at 2007-7-12 3:34:30 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

<h:dataTable border="0" rowClasses="" value="#{Version2$reception2.events}" var="var" width="100%">

<h:column>

<h:selectBooleanCheckbox rendered="#{not var.hasChild}"/>

</h:column>

<h:column>

<f:facet name="header">

<h:outputText style="font-weight: bold" value="Purpose of Registration"/>

</f:facet>

<h:outputLabel value="#{var.name}" onclick="ShowHide2('#{var.eventKeyword}')"/>

<h:dataTable value="#{var.children}" var="childVar" id="...">

<h:column>

<h:selectBooleanCheckbox rendered="#{not childVar.hasChild}"/>

</h:column>

<h:column>

<h:outputText value="#{childVar.name}"/>

</h:column>

</h:dataTable>

I need to set the appropriate id for the nested datatable so that it can be given as an argument to the javascript in the main table. I use Sun JSF 1.1

AshishShakyaa at 2007-7-12 3:34:30 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

I see. You want to prevent the ID's being woodstocked? You can't do it in JSF 1.1.

Rather use the 'this' reference in Javascript and then do a lookup for the child datatable based on the ID of the reference.

Example JSF<h:column>

<h:outputLabel id="label" value="#{var.name}" onclick="showHide(this);">

<h:dataTable id="childTable">

...

</h:dataTable>

</h:column>

JSfunction showHide(element) {

var childTable = document.getElementById(element.id.substring(0, element.id.lastIndexOf(':')) + ':childTable');

childTable.style.display == 'none' ? childTable.style.display = 'block' : childTable.style.display = 'none';

}

BalusCa at 2007-7-12 3:34:30 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
For using reference, i think "this" is better (as BalusC mentioned)If you use <t:dataTable> instead of <h:dataTable>, my solution (above) will work.
jesefa at 2007-7-12 3:34:30 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
Thanks a lot for your help.
AshishShakyaa at 2007-7-12 3:34:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...