Menu

xml/http request

Yann
2006-07-03
2013-04-11
  • Yann

    Yann - 2006-07-03

    I have created the code to populate the content using http request. I am using dwr so I am not sure all my code can be re-used but the principles should be the same.
    I modified wick.js to call function on the page if the collection requested (a variable) has not been defined yet.
    function processSmartInput(inputBox) {
        if ( lastCollectionName != null && inputBox.getAttribute( "dataSrc" ) != null  && inputBox.getAttribute( "dataSrc" ).length > 0 && lastCollectionName != inputBox.getAttribute( "dataSrc" ) ) {
            try {
                updateCollection( eval( inputBox.getAttribute( "dataSrc" ) ) );
            }
            catch ( exception ) {
                retrieveCollection( inputBox.getAttribute( "dataSrc" ) );
                collection = null;
            }
        }
        else if ( lastCollectionName == null && inputBox.getAttribute( "dataSrc" ) != null && inputBox.getAttribute( "dataSrc" ).length > 0  ) {
            try {
                updateCollection( eval( inputBox.getAttribute( "dataSrc" ) ) );
            }
            catch ( exception ) {
                retrieveCollection( inputBox.getAttribute( "dataSrc" ) );
                collection = null;
            }
        }
        if ( collection != null ) {
            lastCollectionName = inputBox.getAttribute( "dataSrc" );
    ...

    here is the code I have on my client.
    function retrieveCollection( tagName ) {
        eval( tagName + ' = new Array()' );
        ClientService.getTagValues( collectionRetrieved, tagName );
    }
    collectionRetrieved is the callback method:
    function collectionRetrieved( tagNameValues ) {
        var tagValues = tagNameValues.tagValues;
        if ( tagValues != null && tagValues.length > 0 ) {
        var valuesArray = "[";
        for ( var i = 0; i < tagValues.length; i++ ) {
            if ( i > 0 ) valuesArray += ", ";
            valuesArray += "'" + tagValues[i] + "'";
        }
        valuesArray += "];";
        eval( tagNameValues.tagName + " = " + valuesArray );
        if ( focusedElement != null && focusedElement.getAttribute( "dataSrc" ) != null && focusedElement.getAttribute( "dataSrc" ) == tagNameValues.tagName ) {
            processSmartInput( focusedElement );
        }
        }
    }
    my code is slightly more complicated because the drop down list is dependent on a preciously entered value. But all you really need to do is update the dataSrc attribute to reflect which collection to retrieve.

    I use the handleFocus and handleBlur to check which element in the form has focus and whether it is expecting a drop-down of the type that has just been retrieved.

    If anybody is interested, I can send the full code.

    Yann

     
    • Dusan Pavlica

      Dusan Pavlica - 2007-03-16

      Hi Yann,
      I am really interested in the full code.
      Would you be so kind to sent it to me please?

       

Log in to post a comment.

MongoDB Logo MongoDB