ajaxstruts2struts2-jqueryjquery-selectboxstruts2-jquery-plugin

How to manipulate the list of a Struts2 <sj:select /> before it is loaded?


I have implemented Struts2-jQuery <sj:select/>.

This select box is populated fetching a JSON object coming from an AJAX call.

How can I access this JSON object before the loading of the SelectBox in javascript in order to do some processing on it?


Solution

  • The Struts2-jQuery-plugin's SelectTag has an attribute for that:

    onBeforeTopic : Topics that are published before a load

    Example of usage:

    <script type="text/javascript">
        $(function(){
            $.subscribe("myBeforeHandler", function(event, data) {
                alert("I'm raised before the loading of the SelectBox ! Data is : " + data);
            });
        });
    </script>
    
    <s:url var="myUrl" action="foobar" namespace="/" />
    
    <sj:select onBeforeTopics = "myBeforeHandler"
                         href = "%{myUrl}"
                         list = "foo"
                         name = "bar" />