6 Replies Latest reply on Sep 30, 2010 3:51 AM by satyasuppu

    How to display the password in astricks in datagrid cell

    satyasuppu Level 1

      Hi.

       

       

        I have a simple datagrid with 3 columns.In that one column is editable..

       

      If i type anything in that editable cell,it should disply in astericks.like password ...

       


      Could you please help me how to do this..

       

       

      Thanks inadvance..

       

       

      Regards

      satya.

        • 1. Re: How to display the password in astricks in datagrid cell
          rootsounds Level 4

          Sounds like you need to specify a custom DataGrid.itemEditor. You would use a custom TextInput control with displayAsPassword defaulted to true.

           

          http://blog.flexexamples.com/2008/01/27/displaying-a-textinput-controls-text-as-a-password -in-flex-redux/

          1 person found this helpful
          • 2. Re: How to display the password in astricks in datagrid cell
            satyasuppu Level 1

            Thank you so much for reply.

             

             

              I want this functionalyity only for few cells based on condition check..

             

              If that condition is true,need to display that cell data in astriks.If it is false,keep it as it iss(meand we can view the data in that cell)..

             

              Can u please give me idea how to do this..

             

             

             

            Thanks ,

            Satya

            • 3. Re: How to display the password in astricks in datagrid cell
              Ratsnackbar Level 2

              You should be able to create two itemrenderers and swap them out based on your condition or even on a specific event like clicking into that cell.

               

              -Joe

              • 4. Re: How to display the password in astricks in datagrid cell
                satyasuppu Level 1

                Hi

                Thanks alot for your reply...

                 

                 

                I ddin't understand what exactly you are saying to achieve this..

                 

                Colud you polease send me sample code for this...

                 

                 

                 

                Thanks,

                SAtya...

                • 5. Re: How to display the password in astricks in datagrid cell
                  Ratsnackbar Level 2

                  Sorry I don't really have time to build and test example code right now but this blog post might have what you want.

                   

                  http://cookbooks.adobe.com/post_Change_Flex_itemRenderer_at_runtime-9063.html

                   

                  It shows the basics of how to swap out an item renderer at runtime.  In your case though you are going to be swapping it out on a line by line basis.  This could get a little tricky and will absolutely slow down your grid if there are too many records.  But it could work.

                   

                  Alternately you may simply want to have one cell in the grid that acts as an indicator to weather the field is editable to the user. Then allow for the user to click on that cell and supply a pop up to modify the password.  This would not slow the system down, would give you an optional point to revalidate the user and would be just as user friendly.  It also has the effect of not allowing someone who is shoulder surfing to be able to inadvertantly see passwords that they should not.  It sounds like in the method you want some passwords would be displayed in plain text.  (Always a bad idea.)

                   

                  -Joe

                  • 6. Re: How to display the password in astricks in datagrid cell
                    satyasuppu Level 1

                    Hi,

                     

                    Thank you so much for you reply..

                     

                     

                    I have tried by using itemRenderer.below is the code..

                    <mx:DataGrid width="549" height="335" id="QuesAnsDG" editable="true">
                                <mx:columns>
                                    <mx:DataGridColumn headerText="Question" dataField="question" wordWrap="true" editable="false"/>
                                    <mx:DataGridColumn  visible="false" dataField="encryptData" />

                                    <mx:DataGridColumn headerText="Answer" dataField="answer" itemRenderer="Components.Maskpwdrenderer" wordWrap="true"  editable="true"/>
                                   

                                   
                                    <mx:DataGridColumn headerText="NeedAnswer" dataField="neededAnswer" wordWrap="true" width="80" editable="false"/>
                                </mx:columns>
                            </mx:DataGrid>

                     

                     

                     

                    Here is the Itemrenderer Code:

                    Maskpwdrenderer.mxml::

                     

                    <?xml version="1.0" encoding="utf-8"?>
                    <mx:HBox  xmlns:mx="http://www.adobe.com/2006/mxml" width="160" height="23">
                       
                         <mx:Script>
                            <![CDATA[
                                import mx.controls.Alert;
                                import util.Session;
                                import mx.utils.StringUtil;
                                import mx.controls.TextInput;       
                               override public function set data(value:Object):void
                                {
                                   
                                    super.data = value; // set the Item Renderer's data object
                                   markPwdAsAstrik();
                                   
                                }
                                public function changePwdASAstrick():void
                                {
                                    if(null!=data.answer)
                                     { 
                                         var ans:String=data.answer;
                                         var enc :String= data.encryptData;
                                         Alert.show("answer::::"+ans+"Encr::::"+enc );
                                        
                                         var pwd :String= data.answer;
                                          
                                           lbl.text=pwd;
                                           if(enc=='Y')
                                          {
                                                lbl.displayAsPassword=true;
                                               lbl.focusIn=lbl.displayAsPassword=true;
                                          }
                                          else
                                          {
                                              lbl.displayAsPassword=false;
                                          }
                                         
                                      }               
                                }
                                
                            
                            ]]>
                        </mx:Script>
                        <mx:TextInput    text="{data.answer}"   width="150"  click="changePwdASAstrick()"  id="lbl" editable="false"/>
                          
                           
                    </mx:HBox>

                     

                     

                     

                    Here i am getting the datagris data from DB and binding it to the Datagrid.

                     

                    ScriptQuestion.java,SriptQuestion.as are the bean classes  ..for setting the data and getting the data..

                     

                    After getting the data from db iam adding it to Arraylist and getting this data in flex result handler method and binding this data to datagrid..

                     

                    By using the above code its working fine...i am able to put astricks to perticular cells..But by defalut in that editable cell i am getting

                    [object ScriptQuestions] value.

                     

                    .why iam getting this value in the editable cell as defalut...I am not  getting any idea.....Please help me..

                     

                     

                     

                    Thanks,

                    Satya..