JSON Data Loader

Data is a Client Side JSON prefetcher, that makes it easy to provide JSON data that is available at render time. The data can also be loaded via Widget.load() at a later time. There is optionally also a callback available on load.

The list elements below are rendered with JavaScript using preloaded data:

    Load via Widget Call
    data.xhtml
    Documentation
    
    <!-- JavaScript method that can render movie titles as li tags -->
    <script>
        function renderMovies(movies) {
            for (var i = 0; i < movies.length; i++) {
                var movie = movies[i];
                var li = document.createElement('li');
                li.appendChild(document.createTextNode(movie.title));
                document.getElementById('movieList').appendChild(li);
            }
        }
    </script>
    
    <!-- Preload movie data and render via JS method, avoids AJAX-call -->
    <t:data value="#{controller.movies}" var="movies" success="renderMovies" />
    
    <!-- Lazy load data to be called by an action later -->
    <t:data value="#{controller.movies}" var="movies" id="movies" success="renderMovies" lazy="true" widgetVar="movieLoader" />
    
    <!-- Button to trigger lazy loading and rendering -->
    <a href="#" class="button" onclick="TW('movieLoader').load()">Load via Widget Call</a>
    
    <!-- Load data by re-rendering, JSF-style -->
    <t:commandButton value="Load by re-rendering Widget" render=":movies"/>

    Data is a Client Side JSON prefetcher, that makes it easy to provide JSON data that is available at render time. The data can also be loaded via Widget.load() at a later time. There is optionally also a callback available on load.

    Info
    Tag name data
    Component type io.tornadofaces.component.Data
    Renderer type io.tornadofaces.component.DataRenderer
    Attributes
    NameDescriptionRequired
    valueThe value expression that will be rendered as a JavaScript objecttrue
    var The client side variable name of the resulting object. Can be left blank if you intend to access the data via Widget.val() only.false
    jsonThe value will be rendered as a JSON object. Default true.false
    lazy A lazy Data object can be retrieved via a call to Widget.load().false
    successClient callback that will be called when the data is available or reloaded. The first argument is the data itself, the other is a boolean indicating wether this was the initial load or not. false
    widgetVar Widget variable name, accessible via TW('widgetVar') and TornadoFaces.widgets.widgetVar. Use this to load() the data or get the data via val(). Note that the Data component must be wrapped in a Form for the load() function to work.false
    Client Side API

    Widget: TornadoFaces.widget.Data

    Method Params Return type Description
    load() function Load or reload the data. If a success callback is configured, it will be called when the data is available.
    isDataAvailable() boolean Checks if data is available. Typically, this will return false if lazy is true and load() has not been called yet.
    val() object Retrieves the data. Also available via the var attribute name.