raudjcholo opened a new issue #622: Problem with binding in functions
URL: https://github.com/apache/royale-asjs/issues/622
 
 
   Hi:
   
   I have a problem with Binding.
   
   My mxml:
   
   ```
   <?xml version="1.0" encoding="utf-8"?>
   <j:SectionContent xmlns:fx="http://ns.adobe.com/mxml/2009";
       xmlns:j="library://ns.apache.org/royale/jewel"
       xmlns:js="library://ns.apache.org/royale/basic"
   >
   
        <fx:Script>
           <![CDATA[
   
               import com.test.app.models.SecurityModel;
               import com.test.app.utils.LanManager;
   
               [Bindable]
               [Inject(source="securityModel", required="true")]
               public var securityModel:SecurityModel;
   
    private function get passwordLabel():String{
                   return securityModel.lang.getRef("Password", true);
               }
   
   
           ]]>
        </fx:Script>
   
       <j:beads>
                <js:SimpleStatesImpl/>
           <j:VerticalCenteredLayout/>
                <js:ContainerDataBinding/>
        </j:beads>
   
       <j:Card visible="true" visible.loginOut="false">
           <j:Form localId="formUserPwd" visible="true" 
visible.loginOut="false">
    <j:HGroup gap="3" itemsVerticalAlign="itemsCentered">
                   <j:Label text="{securityModel.lang.user}" width="80"/>
                   <j:TextInput localId="username" text="">
                   </j:TextInput>
               </j:HGroup>
   <j:HGroup gap="3" itemsVerticalAlign="itemsCentered">
                   <j:Label text="{passwordLabel}" width="80"/>
                   <j:TextInput localId="password" text="">
                       <j:beads>
                           <js:PasswordInputBead/>
                       </j:beads>
                   </j:TextInput>
               </j:HGroup>
               <j:HGroup percentWidth="100" itemsHorizontalAlign="itemsRight">
                   <j:Button text="{securityModel.lang.getRef('entry')}" 
emphasis="primary"/>
               </j:HGroup>
           </j:Form>
       </j:Card>
   
   </j:SectionContent>
   ```
   There are 3 types of binding:
   
   1. **securityModel.lang.user**: this works correctly
   2. **securityModel.lang.getRef('entry')**: this doesn´t work
   3. **passwordLabel**: this is a trick to fix previous mistake
   
   SecurityModel class:
   
   ```
   package com.test.app.models
   {
   
        import com.test.app.beads.models.Model;
       import com.test.app.utils.LanManager;
   
        
        [Bindable]
        public class SecurityModel extends Model
        {
       
   
                private static var _instance:SecurityModel;
                public static function get instance():SecurityModel{
                        return _instance || (_instance = new SecurityModel());
                }
           
           private var _lang:LanManager;
           [Bindable]
           public function get lang():LanManager{ return _lang; }
           public function set lang(value:LanManager):void{ _lang = value; }
   
           /**
                 * Constructor.
                 */
                public function SecurityModel()
                {
                        super();
                        if (_instance) {
                                trace('SecurityModel error');
                                throw new Error("singleton");
                        }
                        _instance = this;
                }
   
           
   
       }
   }
   ```
   
   LanManager class:
   
   ```
   package com.test.app.utils
   {    
        /** Language Manager based on an asociative array */
        [Bindable] 
        public class LanManager extends EventDispatcher
        {
                
                private var _user:String = "user";
   
                public function get user():String
                {
                        return _user;
                }
   
                public function set user(value:String):void
                {
                        _user = value;
                }
   
                
                public function LanManager() {}
                
                
                public function getRef(ref:String=""):String
                {
                        return ref;
                }
                
        }
   
   }
   ```
   
   The classes are simplified.
   
   Why doesn't 2 work? Could it be a bug?
   
   Thanks!!
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to