Friday, March 26, 2010

Xaf tip 12--How to pass parameters between controllers

After working with MVC pattern exposed by Xaf I have realized that the best way to to pass parameters between controllers is by using events like

public class PricePricetypeController:ViewController {

    public event EventHandler<AdjustingPriceTypeEventArgs> AdjustingPriceType;

 

    public void OnAdjustingPriceType(AdjustingPriceTypeEventArgs e)

    {

        EventHandler<AdjustingPriceTypeEventArgs> handler = AdjustingPriceType;

        if (handler != null) handler(this, e);

    }

    protected override void OnFrameAssigned()

    {

        base.OnFrameAssigned();

        Frame.GetController<PersistenceValidationController>().ContextValidating+=OnContextValidating;

    }

 

 

    void OnContextValidating(object sender, ContextValidatingEventArgs contextValidatingEventArgs) {

 

        var adjustingPriceTypeEventArgs = new AdjustingPriceTypeEventArgs(contextValidatingEventArgs.TargetObjects);

        OnAdjustingPriceType(adjustingPriceTypeEventArgs);

    }

But there is also another way of passing parameters by using the following design pattern

var showViewParameters = simpleActionExecuteEventArgs.ShowViewParameters;

 

            var objectSpace = Application.CreateObjectSpace();

            var collectionSource = new CollectionSource(objectSpace, typeof(ShellSite));

            showViewParameters.Context = TemplateContext.View;

            showViewParameters.TargetWindow = TargetWindow.NewModalWindow;

            showViewParameters.Controllers.Add(new MyCustomController(true));

            showViewParameters.CreatedView = Application.CreateListView("Site_ListView", collectionSource, true);

public class MyCustomController : ViewController{

    public MyCustomController():this(false) {

    }

 

    public MyCustomController(bool appropriateContext){

        Active["AppropriateContext"] = appropriateContext;

    }

Subscribe to XAF feed
Subscribe to community feed

DiggIt!
blog comments powered by Disqus