Matt Hosanee's Blog

...
Twitter Updates
The soul...
The feeds...
The links...
Tuesday Sep 19, 2006

BluePrint JSF AJAX autocomplete textfield selection



Not having much experience of Javascript I had a lot of 'fun' trying to utilise the dropdown selection event from the AJAX autocomplete textfield component using Java Studio Creator.


Here is what I learnt...

1] Javascript code is executed on page rendering in a hierarchical way

2] If you receive an error such as "Element x has no properties", it's likely because your trying to accesss an element later in the page and it is not initialised yet. To solve this add a check to see if the component exists first ie.

 if(!document.getElementById("component")) return;


3] The BP AJAX autocompletion component contains two 'virtual' Javascript hooks, ondisplay and onchoose. Onchoose takes selections from the drop-down. NOTE: These are not propagated to the HTML.

4] To call a Javascript function use this
 onchoose="function hi(){return enableMyButton();}"


To test this using Java Studio Creator:

  • Create a Javascript library eg.
     myjavascriptlib.js 


    function enableMyButton() {
      var gotit = document.getElementById("form1:button1");
      if (!gotit) return;
    
      gotit.setDisabled(false);
    
    }
    

  • Add to your project using the menu item "File -> Add exisiting item -> Other item", and cut/paste the added file in the project view into your "Web Pages" node.



  • Drag/drop a "script" element to your page from the "Advanced" section of the palette, and set the URL, selecting your newly added Javascript library.

  • Go to the JSP page view and move the tag into the section, to enable the library for the whole page.



  • Set the
     onchoose 
    function as detailed in [4] above.

  • Comments:

    Post a Comment:
    • HTML Syntax: NOT allowed