users@woodstock.java.net

Re: getElementById in VWP netbeans6.0

From: Brett M. Bergquist <bbergquist_at_canoga.com>
Date: Wed, 26 Dec 2007 16:19:58 -0500

dojo does the replacement in the body onLoad event handler. If your
script waits until that has completed then the "getElementById" will
actually return the replaced text input element and not the span
element. The trick is how to wait. From a past email from Dan Labreque:

    Both Dojo and Woodstock widgets are created during the window.onLoad
    event. This was a change that Dojo forced upon us when upgrading to
    Dojo .9, back for 4.1 build #14. On the plus side, it allows for
    progressive rendering of HTML.

    Although you're code may have used dojo.addOnLoad, there is no
    guarantee that your code will be invoked last. (Other code,
    including Woodstcok widgets also use this function.) I've found that
    it is safer to test if a widget exists before invoking APIs. (I see
    you have used similar code.) For example:

       <head>
           <script type="text/javascript">
               function init() {
                   var domNode = document.getElementById('form1:fc1');
                   if (domNode == null || typeof domNode.setChooseButton
    != "function") {
                       return setTimeout('init();', 10);
                   }
                   domNode.setChooseButton('form1:button1');
               }
           </script>
       </head>
          <body onLoad="init();">

    Note that a similar example exists in the Woodstock release notes.



jokyog1 wrote:
> >From the other forums i came to know that getElementById is no longer working
> with woodstock components in netbenas6.0 as the components are rendered as
> dynamic script tag and not using traditional Html tags.
>
> For example, a text field is rendered as
>
>
> <script type="text/javascript">
> dojo.addOnLoad(function()
> {webui.suntheme.widget.common.replaceElement("form1:textField1",
> {"widgetType":"webui.suntheme.widget.textField","value":"","required":false,"disabled":false,"style":"position:
> absolute; left: 120px; top:
> 48px","visible":true,"valid":true,"size":20,"readOnly":false,"id":"textField1","autoValidate":false});});
> </script>
>
> So, document.getElementById("form1:textField1") returns the "span" element
> not the input text field element.
>
> How can I get a reference to textField element?? Is there a way to do this
> using dojo or jason? I just simply need to use some basic java script on the
> text field. But i am not able to get a reference to it.
>
> Any help would be appreciated.
>