• Dialog Control with computed ID in a CC

    By Jan Christian Krüger 1 decade ago

    Scope: I want to use a dialog control in a CC with a computed id.

     

    I have a dialog control in a CC. The CC has a custom property "dialogID" and the id of the dialog control is computed:

     

    <em>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</em></div>
    
    <em>&lt;xp:view xmlns:xp=&quot;http://www.ibm.com/xsp/core&quot;&nbsp;xmlns:xe=&quot;http://www.ibm.com/xsp/coreex&quot;&gt;</em></div>
    
    <em>&lt;xe:dialog id=&quot;${javascript:compositeData.dialogId}&quot;&gt;</em></div>
    
    <em>EMPTY DIALOG</em></div>
    
    <em>&lt;/xe:dialog&gt;</em></div>
    
    <em>&lt;/xp:view&gt;</em></div>
    

    My Xpage has is simple. I've set the custom property "dialogId" of my CC to "testId" and put a button on the Xpage which should show the dialog:

     

    <em>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</em></div>
    
    <em>&lt;xp:view xmlns:xp=&quot;http://www.ibm.com/xsp/core&quot;&nbsp;xmlns:xc=&quot;http://www.ibm.com/xsp/custom&quot; xmlns:xe=&quot;http://www.ibm.com/xsp/coreex&quot;&gt;</em></div>
    
    <em>&lt;xp:button value=&quot;Label&quot; id=&quot;button1&quot;&gt;</em></div>
    
    <em>&lt;xp:eventHandler event=&quot;onclick&quot; submit=&quot;true&quot;&nbsp;refreshMode=&quot;complete&quot;&gt;</em></div>
    
    <em>&lt;xp:this.action&gt;&lt;![CDATA[#{javascript:getComponent(&quot;testId&quot;).show()}]]&gt;&lt;/xp:this.action&gt;</em></div>
    
    <em>&lt;/xp:eventHandler&gt;&lt;/xp:button&gt;</em></div>
    
    <em>&lt;xc:ccDialogTest dialogId=&quot;testId&quot;&gt;&lt;/xc:ccDialogTest&gt;</em></div>
    
    <em>&lt;/xp:view&gt;</em></div>
    

    This is the error message when I click on the button:

    Error while executing JavaScript action expression
    Script interpreter error, line=1, col=24: Error calling method 'show()' on java class  com.ibm.xsp.extlib.component.dialog.UIDialog'
    Cannot create a view with the initial tag testid as there is no component that id.

    It works when I use a static id for the dialog control.

     

     

    • Dynamic controls need IDs determined at compile time

      By Maire Kehoe 1 decade ago

      Yes, you are correct, the ID cannot be computed at load time in that situation.

      There is a limitation that controls that use dynamic content behavior need to have an ID that is available at compile time.

      For example, for this page:




      EMPTY DIALOG


      EMPTY DIALOG

      If you look at the corresponding .java file, you'll see a method:

              public int getComponentForId(String id) throws NoSuchComponentException {
                  if( "dialog2".equals(id) )
                      return 3;
                  return -1;
              }

      That method is used when dynamically loading the control content into the server-side control tree. At compile time, when that .java file is generated, the ID "dialog2" is available, so it would be possible to dynamically load dialog2. However the ID of the first xe:dialog is not available at compile time (it will only be available later at page load time), so the getComponentForId method which is generated at compile time cannot handle the ID for the first xe:dialog control.

      The controls that use dynamic content behavior are Dynamic Content, In Place Form, Tooltip, Dialog and Mobile Application Page.