[CLOSED] Publish via Bus through DirectEvent

  1. #1

    [CLOSED] Publish via Bus through DirectEvent

    I have passed simple variables (String, Integer) through the MessageBus and ExtraParameters, but never an Array within the data structure.

    On the client side I gather several data items, one of which is a list of selected Ids from a combobox, and publish them via the MessageBus.

    Building the list of product ids from the ComboBox that is multiSelect works, but is there a better way? Produces [31, 64].

    ...
       var products = new Array();
       for (var I = 0; I < App.comboBoxProducts.getSubmitArray().length; i++)
          products.push(App.comboBoxProducts.getSubmitArray()[i].value);
    
       var data = new Array();
       data[0] = Ext.String.trim(App.comments.getValue());
       data[1] = products;
       Ext.net.Bus.publish('RequestDialog.Finalize', data);
    ...
    I have a MessageBusDirectEvent that will catch the message and call the direct event passing the data.

    Am I passing the Array correctly or does it need to be encoded?
    ...
       <ext:MessageBusDirectEvent Name="" onEvent="Finalize">
          <ExtraParams>
             <ext:Parameter Name="Comments" Value="data[0]" Mode="Raw" />
             <ext:Parameter Name="Products" Value="data[1]" Mode="Raw" />
          </ExtraParams>
       </ext:MessageBusDirectEvent>
    ...
    Finally in the direct event I need to iterate of the list of product Ids that were selected.

    When I grab the extraParameter what else do I need to do to get it back into an Array?

       var products = e.ExtraParameters["Products"];
    I will try to put together a simple example if it will help.
    Last edited by Daniil; Jan 06, 2015 at 12:10 PM. Reason: [CLOSED]
  2. #2
    Hi Chris,

    Building the list of product ids from the ComboBox that is multiSelect works, but is there a better way?
    Using the getSubmitArray method is OK, but it looks you can simplify the code just using a ComboBox's getValue method. It appears to return an array that you need.

    Am I passing the Array correctly or does it need to be encoded?
    It is OK without encoding.

    When I grab the extraParameter what else do I need to do to get it back into an Array?
    Please use JSON.Deserialize().
    int[] products = JSON.Deserialize<int[]>(e.ExtraParams["Products"]);
    Here I have put all the pieces together.

    Example
    <%@ Page Language="C#" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.comboBoxProducts.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { 1, "Item 1" },
                    new object[] { 2, "Item 2" },
                    new object[] { 3, "Item 3" }
                };
            }
        }
    
        protected void Finalize(object sender, DirectEventArgs e)
        {
            int[] products = JSON.Deserialize<int[]>(e.ExtraParams["Products"]);
    
            X.Msg.Alert("Finalize", products.Length).Show();
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    
        <script>
            var publish = function () {
                var data = [];
    
                data[0] = "Comments";
                data[1] = App.comboBoxProducts.getValue();
                Ext.net.Bus.publish('RequestDialog.Finalize', data);
            };
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
            <ext:ComboBox
                ID="comboBoxProducts"
                runat="server"
                DisplayField="text"
                ValueField="value"
                MultiSelect="true">
                <Store>
                    <ext:Store runat="server">
                        <Model>
                            <ext:Model runat="server">
                                <Fields>
                                    <ext:ModelField Name="value" Type="Int" />
                                    <ext:ModelField Name="text" />
                                </Fields>
                            </ext:Model>
                        </Model>
                        <Reader>
                            <ext:ArrayReader />
                        </Reader>
                    </ext:Store>
                </Store>
            </ext:ComboBox>
    
            <ext:Button runat="server" Text="Publish">
                <Listeners>
                    <Click Fn="publish" />
                </Listeners>
                <MessageBusDirectEvents>
                    <ext:MessageBusDirectEvent Name="" OnEvent="Finalize">
                        <ExtraParams>
                            <ext:Parameter Name="Comments" Value="data[0]" Mode="Raw" />
                            <ext:Parameter Name="Products" Value="data[1]" Mode="Raw" />
                        </ExtraParams>
                    </ext:MessageBusDirectEvent>
                </MessageBusDirectEvents>
            </ext:Button>
        </form>
    </body>
    </html>
  3. #3
    Perfect. Thank you for the example. Please close the thread.

Similar Threads

  1. Problem publish ext.net
    By Mikhail in forum 2.x Help
    Replies: 2
    Last Post: Mar 13, 2014, 5:29 AM
  2. Bus publish to opener
    By Soy in forum 2.x Help
    Replies: 3
    Last Post: Apr 09, 2013, 3:32 AM
  3. [CLOSED] MessageBus Publish Parameters
    By vgvallee in forum 2.x Legacy Premium Help
    Replies: 19
    Last Post: Mar 05, 2013, 7:34 PM
  4. Publish Errors
    By Juls in forum 1.x Help
    Replies: 2
    Last Post: Jun 16, 2009, 2:54 PM
  5. License - Publish Project
    By leflaco in forum Licensing
    Replies: 2
    Last Post: Apr 23, 2009, 8:31 PM

Posting Permissions