Example E5067
Visible to All Users

XAF - How to show persistent objects in a non-persistent object's view

This example demonstrates how to declare a collection property of a persistent type in a non-persistent class and display it in the UI.

image

Implementation Details

  1. Create a non-persistent class that implements entry fields and use PopupWindowShowAction to display a Detail View of the class instance in a pop-up window.
  2. Extend the class with a collection property that allows user to select items from a list. To read the selection in the Action's Execute event, access the ListPropertyEditor that is the nested List View.
  3. Handle the ObjectSpaceCreated event to create an ObjectSpace that can handle persistent objects (the collection property you added). Review the following documentation article for additional information: How to: Show Persistent Objects in a Non-Persistent Object's View
  4. The pop-up window invoked by the PopupWindowShowAction contains the OK and Cancel buttons implemented in the DialogController. To add other Actions, create a controller for the dialog class and set the Category to PopupActions.

Files to Review

Documentation

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

EFCore/ComplexDialogEF/ComplexDialogEF.Module/Controllers/MyController.cs
C#
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DevExpress.Xpo; using DevExpress.ExpressApp; using DevExpress.ExpressApp.Actions; using DevExpress.Persistent.Base; using DevExpress.ExpressApp.Editors; using ComplexDialogSample.Module.BusinessObjects; namespace ComplexDialogSample.Module.Controllers { public class MyController : ObjectViewController<ListView, Office> { public MyController() { PopupWindowShowAction action = new PopupWindowShowAction(this, "AssignJobs", PredefinedCategory.RecordEdit); action.SelectionDependencyType = SelectionDependencyType.RequireMultipleObjects; action.CustomizePopupWindowParams += new CustomizePopupWindowParamsEventHandler(action_CustomizePopupWindowParams); action.Execute += new PopupWindowShowActionExecuteEventHandler(action_Execute); } void action_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e) { IObjectSpace os = Application.CreateObjectSpace(typeof(OrderTemplate)); e.Context = TemplateContext.PopupWindow; var template = os.CreateObject<OrderTemplate>(); e.View = Application.CreateDetailView(os, template); } void action_Execute(object sender, PopupWindowShowActionExecuteEventArgs e) { OrderTemplate parameters = (OrderTemplate)e.PopupWindow.View.CurrentObject; ListPropertyEditor listPropertyEditor = ((DetailView)e.PopupWindow.View).FindItem("Services") as ListPropertyEditor; IObjectSpace os = Application.CreateObjectSpace(typeof(Team)); Team team = os.GetObject<Team>(parameters.Team); foreach (Office b in e.SelectedObjects) { foreach (Service service in listPropertyEditor.ListView.SelectedObjects) { Order order = os.CreateObject<Order>(); order.DueDate = parameters.DueDate; order.Team = team; order.Office = os.GetObject<Office>(b); order.Service = os.GetObject<Service>(service); } } os.CommitChanges(); } } }
EFCore/ComplexDialogEF/ComplexDialogEF.Module/Module.cs
C#
using System.ComponentModel; using DevExpress.ExpressApp; using DevExpress.ExpressApp.DC; using DevExpress.Persistent.Base; using DevExpress.ExpressApp.Model; using DevExpress.ExpressApp.Actions; using DevExpress.ExpressApp.Editors; using DevExpress.ExpressApp.Updating; using DevExpress.ExpressApp.Model.Core; using DevExpress.ExpressApp.Model.DomainLogics; using DevExpress.ExpressApp.Model.NodeGenerators; namespace ComplexDialogEF.Module; // For more typical usage scenarios, be sure to check out https://docs.devexpress.com/eXpressAppFramework/DevExpress.ExpressApp.ModuleBase. public sealed class ComplexDialogEFModule : ModuleBase { public ComplexDialogEFModule() { // // ComplexDialogEFModule // RequiredModuleTypes.Add(typeof(DevExpress.ExpressApp.SystemModule.SystemModule)); RequiredModuleTypes.Add(typeof(DevExpress.ExpressApp.Objects.BusinessClassLibraryCustomizationModule)); } public override IEnumerable<ModuleUpdater> GetModuleUpdaters(IObjectSpace objectSpace, Version versionFromDB) { ModuleUpdater updater = new DatabaseUpdate.Updater(objectSpace, versionFromDB); return new ModuleUpdater[] { updater }; } public override void Setup(XafApplication application) { base.Setup(application); application.ObjectSpaceCreated += Application_ObjectSpaceCreated; // Manage various aspects of the application UI and behavior at the module level. } private void Application_ObjectSpaceCreated(object sender, ObjectSpaceCreatedEventArgs e) { CompositeObjectSpace compositeObjectSpace = e.ObjectSpace as CompositeObjectSpace; if (compositeObjectSpace != null) { if (!(compositeObjectSpace.Owner is CompositeObjectSpace)) { compositeObjectSpace.PopulateAdditionalObjectSpaces((XafApplication)sender); } } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.