title: How to use OData metadata for type definition during binding in SAPUI5?
body: <p>I build a method that allows me to get a data type according to the odata metadata model.</p>
  
  <p>This method works like this:</p>
  
  <ol>
  <li>read the metadata from odata service</li>
  <li>search for the entity type</li>
  <li>search for the property</li>
  <li>map the Edm:* to some default value (if possible it uses further metadata information)</li>
  <li>return the data type</li>
  </ol>
  
  <p>My problem is now, that metadata is loaded asynchronous.</p>
  
  <p>Therefore I register to <code>attachMetadataLoaded</code> during startup to ensure the data is loaded if the method is used first time.</p>
  
  <p>This lead to the fact of a blank start up screen for some seconds.</p>
  
  <p>Example of my current solution:</p>
  
  <p>In a view:</p>
  
  <pre><code>new sap.m.Input({
    value : {
       path : "/Entity/Property",
       type : Some.Object.getTypeFor("Entity", "Property")
    } 
  });
  </code></pre>
  
  <p>The function would work like this:</p>
  
  <pre><code>function getTypeFor(sEntity, sProperty) {
     var oMetaData = oModel.getServiceMetadata();
     // search for sEntity and in there for sProperty inside the oMetaData
     var oPropertyMeta = ...
     switch (oPropertyMeta.type) {
       case "Edm:String" :
              var oConstraints = {};
              if (property.maxLength) {
                  oConstraints.maxLength = Number(property.maxLength);
              }
          return new sap.ui.model.type.String(null, oConstraints);
       ...
     }
  </code></pre>
  
  <p>Is there a way to wait (inside the function) if metadata is not loaded?
  Or a smarter way to get some default type for a binding according to the metadata?</p>
  
  <h2>Edit</h2>
  
  <p>I am using the v2.odatamodel, there the metadata will be loaded async.
  Looks like the smartfield will also not work correct in that case?</p>