ViewIdPropertyEditor. Getting Started

In this lesson we will create a simple class, which will expose View.Id string property. And then ViewIdPropertyEditor will be assigned for this property. Follow the steps described below.

  • Add a ObjectWithStringViewId business-class in your XAF-application. Use following code:
  • c#
  • VB

[DefaultClassOptions]
public class ObjectWithStringViewId : BaseObject
{
  public ObjectWithStringViewId(Session session)
    : base(session)
  {
  }
  private string _name;
  private int _number;
  private string _viewId;
  public string Name
  {
    get
    {
      return this._name;
    }
    set
    {
      this.SetPropertyValue("Name", ref this._name, value);
    }
  }
  public string ViewId
  {
    get
    {
      return this._viewId;
    }
    set
    {
      this.SetPropertyValue("ViewId", ref this._viewId, value);
    }
  }
  public int Number
  {
    get
    {
      return this._number;
    }
    set
    {
      this.SetPropertyValue("Number", ref this._number, value);
    }
  }
}

<DefaultClassOptions> _
Public Class ObjectWithStringViewId
  Inherits BaseObject
  Public Sub New(ByVal session As Session)
    MyBase.New(session)
  End Sub
  Private __name As String
  Private __number As Integer
  Private __viewId As String
  Public Property Name As String
    Get
      Return Me.__name
    End Get
    Set
      Me.SetPropertyValue("Name", Me.__name, value)
    End Set
  End Property
  Public Property ViewId As String
    Get
      Return Me.__viewId
    End Get
    Set
      Me.SetPropertyValue("ViewId", Me.__viewId, value)
    End Set
  End Property
  Public Property Number As Integer
    Get
      Return Me.__number
    End Get
    Set
      Me.SetPropertyValue("Number", Me.__number, value)
    End Set
  End Property
End Class

  • Create a number of objects using the next updater:
  • c#
  • VB

public class Updater : ModuleUpdater
{
  public Updater(IObjectSpace objectSpace, Version currentDBVersion)
    : base(objectSpace, currentDBVersion)
  {
  }
  public override void UpdateDatabaseAfterUpdateSchema()
  {
    base.UpdateDatabaseAfterUpdateSchema();
    this.CreateObjectsWithStringViewId();
  }
  private void CreateObjectsWithStringViewId()
  {
    var objects = this.ObjectSpace.GetObjects<ObjectWithStringViewId>();
    if (objects.Count >= 1)
      return;
    var obj = this.ObjectSpace.CreateObject<ObjectWithStringViewId>();
    obj.Name = "Object with 'ListView' id";
    obj.Number = 1;
    obj.ViewId = "ObjectWithStringViewId_ListView";
    this.ObjectSpace.CommitChanges();
    var obj1 = this.ObjectSpace.CreateObject<ObjectWithStringViewId>();
    obj1.Name = "Object with 'DetailView' id";
    obj1.Number = 2;
    obj1.ViewId = "ObjectWithStringViewId_DetailView";
    this.ObjectSpace.CommitChanges();
    var obj2 = this.ObjectSpace.CreateObject<ObjectWithStringViewId>();
    obj2.Name = "Object with not existed view id";
    obj2.Number = 3;
    obj2.ViewId = "Hello from Xafari ;)";
    this.ObjectSpace.CommitChanges();
  }
}

Public Class Updater
  Inherits ModuleUpdater
  Public Sub New(ByVal objectSpace As IObjectSpace, ByVal currentDBVersion As Version)
    MyBase.New(objectSpace, currentDBVersion)
  End Sub
  Public Overrides Sub UpdateDatabaseAfterUpdateSchema()
    MyBase.UpdateDatabaseAfterUpdateSchema()
    Me.CreateObjectsWithStringViewId()
  End Sub
  Private Sub CreateObjectsWithStringViewId()
    Dim objects = Me.ObjectSpace.GetObjects(Of ObjectWithStringViewId)()
    If objects.Count >= 1 Then
      Return
    End If
    Dim obj = Me.ObjectSpace.CreateObject(Of ObjectWithStringViewId)()
    obj.Name = "Object with 'ListView' id"
    obj.Number = 1
    obj.ViewId = "ObjectWithStringViewId_ListView"
    Me.ObjectSpace.CommitChanges()
    Dim obj1 = Me.ObjectSpace.CreateObject(Of ObjectWithStringViewId)()
    obj1.Name = "Object with 'DetailView' id"
    obj1.Number = 2
    obj1.ViewId = "ObjectWithStringViewId_DetailView"
    Me.ObjectSpace.CommitChanges()
    Dim obj2 = Me.ObjectSpace.CreateObject(Of ObjectWithStringViewId)()
    obj2.Name = "Object with not existed view id"
    obj2.Number = 3
    obj2.ViewId = "Hello from Xafari ;)"
    Me.ObjectSpace.CommitChanges()
  End Sub
End Class

  • Add modules XafariModule and XafariEditorsModule to Module Project.
  • Add modules Xafari.WinModule and Xafari.Editors.WinModule to the Windows Forms Application Project.
  • Add modules Xafari.Editors.Web and Xafari.Web to the Web Application Project.
  • Invoke Model Editor. Navigate to BOModel|ViewIdPropertyEditorSample.Module.BusinessObjects|ObjectWithStringViewId|OwnMembers|ViewId node. Set PropertyEditorType property to Xafari.Editors.Win.WinViewIdPropertyEditor (or Xafari.Editors.Web.WebViewIdPropertyEditor).

viewid_property_editor_3

  • To see the result, run the WinForms or ASP.NET application.

Windows Forms:

viewid_property_editor_4

ASP.NET:

viewid_property_editor_5

  • You can set the type of View that will be visible in the lookup list. For this purpose use DataSourceCriteria property as shown in the image below.

viewid_property_editor_6

The following filter criteria are available:

  • ListView
  • DetailView
  • Any
  • DashboardView

You can download the solution used in this lesson.