0

How do I determine the absolute id of the organizationUnit(from /webapp/resources/acme/organizationUnit.xhtml)? When I select a node from the tree, the organizationUnit should display the selected node. I can't use a relative id because the p:ajax element is not in the same naming container with the organizationUnit component. I need to use absolute id in this case. With Firebug the id of the component is tabs:0:editorsGroup:4:editor3:accountWindowsContainer:organizationUnit. Isn't :form:tabs:editorsGroup:editor:accountWindowsContainer:organizationUnit the absolute id of the component?

EDIT1

custom:include is configured as follows:

<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC
"-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
"http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
<facelet-taglib>
    <namespace>http://acme.com/custom</namespace>
    <tag>
        <tag-name>include</tag-name>
        <component>
            <component-type>com.acme.custom.DynamicInclude</component-type>
            <handler-class>com.acme.client.custom.tags.DynamicIncludeHandler</handler-class>          
        </component>        
    </tag>   
</facelet-taglib>  

@FacesComponent("com.geneous.custom.DynamicInclude")
public class DynamicInclude extends javax.faces.component.UIComponentBase{ ... }

public final class DynamicIncludeHandler extends javax.faces.view.facelets.ComponentHandler { ... }

Mojarra 2.0.8 is used.

/WEB-INF/flows/actions-acc-flow/accounts.xhtml

<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    template="/WEB-INF/layouts/standard.xhtml">

    <ui:define name="content">
        <h:form id="form" prependId="false">
            <!-- messages -->
        <p:growl id="msgs" showDetail="true" />
                 ...
            <h:panelGroup id="mainPanel">
                <ui:include src="/WEB-INF/flows/actions-acc-flow/genericAccountsTable.xhtml" />
            </h:panelGroup>
        </h:form>
    </ui:define>
</ui:composition>

/WEB-INF/flows/actions-acc-flow/genericAccountsTable.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">

    <h:outputScript library="primefaces" name="primefaces.js" />
    <h:outputStylesheet library="primefaces" name="primefaces.css" />

    <p:dataTable id="genericAccounts"
    ...
    </p:dataTable>
    <p:spacer height="1" />
    <p:toolbar>
        <p:commandButton value="#{label.add}"
            action="#{accountsBean.initializeEntity}" immediate="true"
            update=":form:actionsDialog :form:msgs"
            oncomplete="actionsDialog.show()">                  
        </p:commandButton>              
    </p:toolbar>
    <ui:include src="/WEB-INF/flows/actions-acc-flow/mainDialog.xhtml" />
    ...
</ui:composition>

/WEB-INF/flows/actions-acc-flow/mainDialog.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">

    <p:dialog id="actionsDialog" widgetVar="actionsDialog"
        dynamic="true" modal="true">
    ...
        <ui:include src="/WEB-INF/flows/actions-acc-flow/genericAccount.xhtml"/>
        ...
    </p:dialog>
</ui:composition>

/WEB-INF/flows/actions-acc-flow/genericAccount.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:c="http://java.sun.com/jstl/core"
    xmlns:custom="http://geneous.com/custom">
    <p:tabView id="tabs" value="#{accountsBean.groups}" var="group">
        <p:tab title="#{eval.getString(group.name)}">
            <p:dataTable id="editorsGroup" value="#{group.editors}" var="editor">
                <p:column>
                    <custom:include src="#{editor.component}" id="editor">
                        <ui:param name="beanName" value="#{editor.beanName}" />
                        <ui:param name="enabled" value="#{editor.enabled}" />
                        <ui:param name="mandatory" value="#{editor.mandatory}" />
                        <ui:param name="name" value="#{editor.name}" />
                    </custom:include>
                </p:column>
            </p:dataTable>
        </p:tab>
    </p:tabView>
</ui:composition>

/WEB-INF/flows/editors/accountsWindowsContainer.xhtml(this file is stored in editor.component and included from genericAccount.xhtml)

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:acme="http://java.sun.com/jsf/composite/acme">

    <acme:organizationUnit bean="#{windowsContainer}" mandatory="#{mandatory}"
        name="#{name}" id="accountWindowsContainer" />  
</ui:composition>

/webapp/resources/acme/organizationUnit.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:composite="http://java.sun.com/jsf/composite"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">
    <!-- INTERFACE -->
    <composite:interface>
        <composite:attribute name="bean" type="java.lang.Object" required="true" />
        <composite:attribute name="mandatory" type="boolean" required="true"/>
        <composite:attribute name="name" type="java.lang.String" required="true" />
    </composite:interface>
    <!-- IMPLEMENTATION -->
    <composite:implementation>
        <h:panelGrid columns="2">
            <h:outputText value="#{cc.attrs.name}: #{cc.attrs.mandatory ? '*' : ''}" />
            <p:tree value="#{cc.attrs.bean['root']}" var="node" 
                selectionMode="single" selection="#{cc.attrs.bean['selectedNode']}">
                <p:ajax event="select" listener="#{cc.attrs.bean['onNodeSelect']}"
                    update="absolute_id_of_organization_unit" />
                <p:treeNode>
                    <h:outputText value="#{node}" />
                </p:treeNode>
            </p:tree>
            <h:outputText />
            <p:inputText id="organizationUnit"
                value="#{cc.attrs.bean['selectedItemPath']}"
                disabled="true" />
        </h:panelGrid>
    </composite:implementation>
</html>  
Seitaridis
  • 4,459
  • 9
  • 53
  • 85

1 Answers1

3

Isn't :form:tabs:editorsGroup:editor:accountWindowsContainer:organizationUnit the absolute id of the component?

That's it only if you remove prependId="false" from the <h:form> and if you can assure that your <custom:include> implements NamingContainer. If the latter isn't true, then you need to remove the :editor part from the absolute ID.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • If I don't remove the prependId="false" and implements the NamingContainer, the absolute id will be :tabs:editorsGroup:editor:accountWindowsContainer:organizationUnit? – Seitaridis Oct 02 '12 at 12:33
  • The `prependId="false"` must in any way be removed in order to get this construct to work. The `prependId` is merely client side, not server side. You have to use `:form` in front and it'll find the component in server side regardless of the `prependId` setting, but when it's set to `false`, JS/ajax in client side won't be able to locate it in order to update it. – BalusC Oct 02 '12 at 12:35
  • When a node is selected, onNodeSelected event, the selectedItemPath property is updated with the new value and the update statement should update the organizationUnit component after a node is selected. – Seitaridis Oct 02 '12 at 12:48
  • In genericAccountTable.xhtml, before the *genericAccounts* datatable there is a ``. If I remove the `prependId="false"` and use the above absolute id, with of without `editor`, the preRenderView method will be called continuously. – Seitaridis Oct 03 '12 at 06:39
  • Please define "continuously". This listener method is supposed to be invoked once time right before every render response phase. – BalusC Oct 03 '12 at 10:20
  • The preRenderView method is executed over and over again. After it finishes, it starts over again. – Seitaridis Oct 03 '12 at 10:35
  • Naming containers add row information to the generated id. I have made my own function(http://stackoverflow.com/questions/14776402/retrieve-client-id-for-facelets) that strips off row index information and now the update works. – Seitaridis Feb 12 '13 at 13:32