Spring.net Bidirectional Binding with many Models(多Model绑定)

代码


public   partial   class  Son1 : Spring.Web.UI.Page
{

    
public  DaughtEntity Daught {  get set ; }
    
public  SonEntity Son {  get set ; }

    
public  Dictionary < string object >  DictStorage  =   null ;

    
protected   override   void  InitializeDataBindings()
    {
        BindingManager.AddBinding(
" txtSonName.Text " " Son.SonName " );
        
// 从View 到 Model
        BindingManager.AddBinding( " txtSonAge.Text " " Son.SonAge " ,Spring.DataBinding.BindingDirection.SourceToTarget);
        BindingManager.AddBinding(
" txtSonBirthday.Text " " Son.SonBirthday " );

        BindingManager.AddBinding(
" txtDaughtName.Text " " Daught.Name " );
        BindingManager.AddBinding(
" txtDaughtAge.Text " " Daught.Age " );
        BindingManager.AddBinding(
" txtDaughtBirthday.Text " " Daught.Birthday "
            ,
new  Spring.Globalization.Formatters.DateTimeFormatter( " yyyy$MM$dd hh:mm:ss " ,Master.UserCulture));
    }
    
protected   override   void  InitializeModel()
    {
        DictStorage 
=   new  Dictionary < string object > ();

        Daught 
=   new  DaughtEntity();
        Daught.Name 
=   " 公主 " ;
        Daught.Age 
=   13 ;
        Daught.Birthday 
=  DateTime.Parse( " 2015-01-17 " );

        Son 
=   new  SonEntity();
        Son.SonName 
=   " 我儿子 " ;
        Son.SonAge 
=   15 ;
        Son.SonBirthday 
=  DateTime.Parse( " 2014-01-17 " );

        DictStorage.Add(
" MyDaught " , Daught);
        DictStorage.Add(
" MySon " , Son);
    }

    
protected   override   void  LoadModel( object  savedModel)
    {
        DictStorage 
=  (Dictionary < string object > )savedModel;
        Daught
=  DictStorage[ " MyDaught " as  DaughtEntity;
        Son 
=  DictStorage[ " MySon " as  SonEntity;
    }
    
protected   override   object  SaveModel()
    {
        
return  DictStorage;
    }    
    
protected   void  Button1_Click( object  sender, EventArgs e)
    {
        lblDaughtName.Text 
=  Daught.Name;
        lblDaughtBirthday.Text 
=  Daught.Birthday.ToString();
        lblSonName.Text 
=  Son.SonName;
        lblSonName.Text 
=  Son.SonBirthday.ToString();
    }
    
protected   void  Page_Load( object  sender, EventArgs e)
    {       

    }
}

 

/Files/wucg/_TestProjects/多Model双向绑定TestSpringBiderectBindSite.zip

 

你可能感兴趣的:(spring)