Presenter is Null need help

Topics: CAB & Smart Client Software Factory
May 10, 2007 at 8:39 PM
I have a service that I am using to control moving between a set of views. When my program loads, it loads the first view into the workspace just fine. I select the different controls and then move on to the next view. On doing so, it crashes on the next views presenter.OnViewReady() saying that the presenter is null. Is this happening because I am not doing an AddNew<View>? If so, how can I dynamically add a new view? I have an array with all my views in it, but I can't do (UserControl)MyArrayi View = WorkItem.SmartParts.AddNew<(UserControl)MyArrayi>(); right?

If anyone could help I'd much appreciate it.
May 11, 2007 at 9:22 AM
Hi,
I think if you use CreateNew attribute on your presenter, you have to add the view to your WorkItem. In your module controller :
(YourViewClass)MyArrayi view = WorkItem.SmartParts.AddNew<YourViewClass>("MyView");
WorkItem.WorkSpaces"MyWorkSpace".Show(view);

I think it's work ...

Fred
May 11, 2007 at 5:38 PM
The View has to be added in the WorkItem since WorkItem is the Container for DI(Dependency Injection) system it will inject the presenter reference when you add the view in to the container.But it is not mandatory that you need to add the view in the module controller.You can add at any time at runtime but make sure you are not calling the View before adding in to the WorkItem.

Hope this helps you

Thnx
Mani
May 11, 2007 at 6:13 PM
See, that's what's strange. I added the view in the module controller, and it still is null. I'll try a couple things here, but I'm guessing that it's not in the workitem as you guys said.
May 11, 2007 at 9:10 PM
You should be careful in which workitem you are adding the view,If you adding your view to RootWorkItem that is the WorkItem reference available in your module controller.Then you have pull the view from the rootworkitem or else if you are adding view to you custom workitem then you need to pull the view from the custom workitem.

CustomWorkItem.SmartParts.AddNew<MyView>("MyView");

your code for pulling the view shoould be
CustomWorkItem.SmartParts.Get<MyView>("MyView")

May 12, 2007 at 7:36 AM

kuralmani wrote:
You should be careful in which workitem you are adding the view,If you adding your view to RootWorkItem that is the WorkItem reference available in your module controller.Then you have pull the view from the rootworkitem or else if you are adding view to you custom workitem then you need to pull the view from the custom workitem.

CustomWorkItem.SmartParts.AddNew<MyView>("MyView");

your code for pulling the view shoould be
CustomWorkItem.SmartParts.Get<MyView>("MyView")




Right, but if I have an array of views MyArray(new MyView1, new MyView2(), and I want to dynamically add the view based on the view that I am currently on, I can't do (MyArrayi view = WorkItem.SmartParts.Addnew<MyArrayi>();) right? So how can I properly declare that?
May 14, 2007 at 3:39 PM
In thats case use Add mehtod

foreach(Form form in YourArray)
{
WorkItem.SmartParts.Add(form."ID")
}
May 14, 2007 at 6:41 PM

kuralmani wrote:
In thats case use Add mehtod

foreach(Form form in YourArray)
{
WorkItem.SmartParts.Add(form."ID")
}


Wow, I can't believe I didn't think of that. You are the man :)