title: SAP UI5: Fill XML-Dropdown dynamically using Lifecycle Hook Function
body: <p>I've done the <a href="http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/8022ac87-1f60-3110-5383-fa68a91d7f8b?QuickLink=index&amp;overridelayout=true&amp;59017145622993" rel="nofollow" title="Building SAP Fiori-like UIs 
  with SAPUI5">Tutorial</a> for building Fiori-like UIs with SAPUI5 and tried adding a <a href="http://i.stack.imgur.com/LXJEu.png" rel="nofollow">sort-function</a>.</p>
  
  <p>The Dropdown-Box is filled with the Names of the JSON-Model-Data:</p>
  
  <pre><code>{
  "SalesOrderCollection": [
      {
          "SoId": "300000097",
          "ApprovalStatus": "",
          "Status": "Initial",
          "ConfirmationStatus": "",
          "BillingStatus": "Initial",
          ...
          } ...
  </code></pre>
  
  <p>I implemented this function in my View Controller to fill the dropdown:</p>
  
  <pre><code>    fillDropdown : function(evt) {
  
      // Get current view and dropdownbox
      var oView = this.getView();
      var oDropdown = oView.byId("ddbox");
  
      // Get names of nodes in model
      var metaArray = Object.getOwnPropertyNames(oView.getModel()
              .getProperty("/SalesOrderCollection/0"));
  
      // Add every name to dropdownbox
      var arrayLength = metaArray.length;
      for ( var i = 0; i &lt; arrayLength; i++) {
          oDropdown.addItem(new sap.ui.core.ListItem("item" + i)
                  .setText(metaArray[i]));
      }
  }
  </code></pre>
  
  <p>Finally, here comes my problem:</p>
  
  <p>How can I run this function automatically when the View gets rendered? I know the lifecycle hook functions onInit &amp; onBeforeRendering but I can't use them in my XML-View:</p>
  
  <p>I can register the eventhandler for UI-Elements like here:</p>
  
  <pre><code>&lt;uicom:DropdownBox id="ddbox" editable="true" change="handleListSort"&gt;
  </code></pre>
  
  <p>But not for the View or the Page like I tried here:</p>
  
  <pre><code>&lt;Page title="myPage" onBeforeRendering="fillDropdown"&gt;
  
  &lt;core:View controllerName="sap.ui.demo.myFiori.view.Master" (...) onBeforeRendering="fillDropdown"&gt;
  </code></pre>
  
  <p>Possible dirty workaround: Call the function when clicking on the Sort-Button in the IconTabBar</p>
  
  <pre><code>&lt;IconTabBar select="fillDropdown"&gt;
  </code></pre>
  
  <hr>
  
  <p>Thanks for your help!</p>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p>If I used a JavaScript-View instead of an XML-View, I could simply implement my fillDropdown function in the onAfterRendering function of my View.
  But why do XML Views not throw lifecycle hook events?</p>
  
  <hr>
  
  <p><strong>Update 2</strong></p>
  
  <p>I also can't use the onAfterRendering of my View Controller; <code>oView.getModel().getProperty("/SalesOrderCollection/0");</code> returns no object because the content of my model is (whyever) only available after the hook functions.</p>