Print Page | Close Window

Reusing SimpleSearcher in a Tab Control

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=620
Printed Date: 11-Jun-2026 at 9:18am


Topic: Reusing SimpleSearcher in a Tab Control
Posted By: orcities
Subject: Reusing SimpleSearcher in a Tab Control
Date Posted: 17-Dec-2007 at 9:40am
I am trying to reuse the SimpleSearcher in a tab control environment. In looking at the SearchSummary..Controller I came up with the code below.
 
THE PROBLEM: When I run the application I get an error when the grids BindingManagers.BindingSource is set tot he source that is being passed from the searcher. The grids BM.BS is correct but the source being passed is that of the PageController not the TabController that it is on. I have not found where it runs bad. I have stepped through it. All values being passed are correct. It is somewhere where the Searcher is added to ViewFactory. Everything prior to that is correct.
 
In the configure context core method of the tab controller:

//Searcher

SearcherViewController.CreateSearcherViews(AssignmentBindingSource, GlobalService.EntityManager);

ViewFactory.AddNew(Constants.ViewNames.SimpleSearcher, WorkItem, SearcherViewId);

SearcherViewController is the same as it is in the SearchSummary...Controller class except I am not using generics as the search object type.

#region SearcherViewController

 

        /// <summary>Get the SearcherViewController.</summary>

        protected ISearcherViewController SearcherViewController

        {

            get

            {

                if (mSearcherViewController == null)

                {

                    CreateSearcherViewController();

                }

                return mSearcherViewController;

            }

        }

 

        /// <summary>Create the SearcherViewController.</summary>

        /// <example>

        /// <![CDATA[

        /// protected override ISearcherViewController CreateSearcherViewController() {

        ///   CreateSearcherViewController<UserSearcher>();

        ///   AddSearchResultsViewContext(); // optional configuration step

        /// }

        /// ]]>

        /// </example>

        protected void CreateSearcherViewController()

        {

            ISearcherViewController searcherController = CreateSearcherViewController<OrganizationSearcher>();

           

        }

 

        /// <summary>Creates a new <see cref="ISearcherViewController"/>.</summary>

        /// <remarks>

        /// Creates an <see cref="ISearcherViewController"/>,

        /// adds it to the <see cref="WorkItemController.WorkItem"/>, and

        /// Sets <see cref="SearcherViewController"/>.

        /// </remarks>

        protected virtual LOC.CEMS.Foundation.SearcherViewController<Organization, TSearcher> CreateSearcherViewController<TSearcher>()

          where TSearcher : ISearcher, new()

        {

            LOC.CEMS.Foundation.SearcherViewController<Organization, TSearcher> svc =

              WorkItem.Items.AddNew<LOC.CEMS.Foundation.SearcherViewController<Organization, TSearcher>>();

            svc.SetSearchResultsViewId(AssignmentViewId);

            svc.SetSearchViewId(SearcherViewId);

            mSearcherViewController = svc;

           

            return svc;

        }

 

        #endregion

 



Replies:
Posted By: orcities
Date Posted: 17-Dec-2007 at 9:49am
The only place I see as referencing the PageController is the WorkItem. But I don't see in the SearcherViewController where it needs anything from WorkItem. It only loads the control to ViewFactory referencing the WorkItem.


Posted By: orcities
Date Posted: 18-Dec-2007 at 8:44am

I bypassed the page problem to see if the controls would load. I do get the grid to load but the simple search does not.

 
Bill whats up?


Posted By: orcities
Date Posted: 18-Dec-2007 at 9:12am
Ok,
 
I made a modification to my ViewControl to have the smartpartplaceholder.smartpartnames for the results area and the search area to be the

WorkspaceNames.SearchResultsViewSmartPartPlaceholder

and

WorkspaceNames.SearchViewSmartPartPlaceholder

This finally got the controls to show and work. I still have to get past the page bindingsource type.
 
It just will not use the binding source type of the tab. It seems to default back to the page. I can not figure out why.
 
IdeaBlade please help.


Posted By: orcities
Date Posted: 18-Dec-2007 at 10:52am
Tx for the help....
 
The change above worked I changed my page object back and all worked fine.


Posted By: Bill Jensen
Date Posted: 18-Dec-2007 at 2:44pm

Hi Dan,

It sounds like you got some advice from somewhere.
 
Is the problem solved?
 
Bill J.


Posted By: orcities
Date Posted: 18-Dec-2007 at 3:06pm

I was being sarcastic. I have solved it for the most part but, I am still having one issue.

"An object with this ID already exists: SearchResultsViewSmartPartPlaceholder_ViewContext."
 
Since adding the search feature to a tab it gives me an error when I add the second tab. The same problem we got with the other tab issues, duplicate name exists.
 
The problem is that I didn't create that module so I need to figure out how to solve it. In the ThreePanel Example we made the SmartPartPlaceholder.SmartPartName = null.
 
Suggestions...
 
 


Posted By: orcities
Date Posted: 26-Dec-2007 at 9:59am
Bill,
 
Have any advice. On how to get the simple searcher to load on multiple tabs w/out throwing the error in question?


Posted By: orcities
Date Posted: 03-Jan-2008 at 2:03pm
Bill,
I know you are busy but can you give me some insight?


Posted By: Bill Jensen
Date Posted: 03-Jan-2008 at 3:32pm

Where is your SearchViewId coming from in the line

ViewFactory.AddNew(Constants.ViewNames.SimpleSearcher, WorkItem, SearcherViewId);
 
You'll need a unique view id for each instance of the searcher.
 
Also, what is AssignmentViewId doing in an Organization searcher:
 
LOC.CEMS.Foundation.SearcherViewController<Organization, TSearcher> svc =

              WorkItem.Items.AddNew<LOC.CEMS.Foundation.SearcherViewController<Organization, TSearcher>>();

svc.SetSearchResultsViewId(AssignmentViewId);
 
Bill J.


Posted By: orcities
Date Posted: 03-Jan-2008 at 3:47pm
That code is not up to date.
The only way I could get it to work at all was to use the WorkspaceNames that were the default in the Search Control. Those being (below).
 
 

mAssignmentSmartPartPlaceholder.SmartPartName = Constants.WorkspaceNames.SearchResultsViewSmartPartPlaceholder;//FourPanelViewContext.AssignmentViewId;

           

            mSearcherSmartPartPlaceholder.SmartPartName = Constants.WorkspaceNames.SearchViewSmartPartPlaceholder;//FourPanelViewContext.SearcherViewId;

I have also tried overriding the values form the SearchResults and the SearchView. But that didn't work either.
 
I have also set the mSearcherSmartPartPlaceholder.Name and mAssignmentSmartPartPlaceholder.Name = null. To eliviate the double problem I had discovered earlier and you were nice enough to explain how to fix it.

 

The Id's come from the ViewContext I have associated.

            public string SearcherViewId

            {

                  get { return (mSearcherViewId != null) ? mSearcherViewId : mSearcherSmartPartName; }

                  set { mSearcherViewId = value; }

            }

 

            public string AssignmentViewId

            {

                  get { return (mAssignmentViewId != null) ? mAssignmentViewId : mAssignmentSmartPartName; }

                  set { mAssignmentViewId = value; }

            }



Posted By: orcities
Date Posted: 08-Jan-2008 at 10:05am

Bill,

When I create my own Id’s for the searcher and the search results, I can get the result grid to display but not the searcher. Below is my code. When I use the default names for the SmartPartPlaceholders I get both the searcher and the grid but I can only have one tab visible at a time.

View.cs
protected override void PresenterReady(EventArgs e)

{

mAssignmentSmartPartPlaceholder.Name = null;

      mChildSmartPartPlaceholder.Name = null;

      mPreviewSmartPartPlaceholder.Name = null;

      mSearcherSmartPartPlaceholder.Name = null;

 

      mChildSmartPartPlaceholder.SmartPartName = FourPanelViewContext.ChildViewId;

      mAssignmentSmartPartPlaceholder.SmartPartName = FourPanelViewContext.AssignmentViewId; //Constants.WorkspaceNames.SearchResultsViewSmartPartPlaceholder

      mPreviewSmartPartPlaceholder.SmartPartName = FourPanelViewContext.PreviewViewId;

      mSearcherSmartPartPlaceholder.SmartPartName = FourPanelViewContext.SearcherViewId; //Constants.WorkspaceNames.SearchViewSmartPartPlaceholder;

}

Context.cs
public string SearcherViewId

{

      get { return (mSearcherViewId != null) ? mSearcherViewId : mSearcherSmartPartName; }

      set { mSearcherViewId = value; }

}

 

public string AssignmentViewId

{

      get { return (mAssignmentViewId != null) ? mAssignmentViewId : mAssignmentSmartPartName; }

      set { mAssignmentViewId = value; }

}

TabController.cs
#region SearcherViewController

 

protected ISearcherViewController SearcherViewController

{

get

      {

            if (mSearcherViewController == null)

            {

               CreateSearcherViewController();

            }

            return mSearcherViewController;

}

}

 

protected void CreateSearcherViewController()

{

ISearcherViewController searcherController = CreateSearcherViewController<OrganizationPageSearcher>();

           

}

 

protected virtual LOC.CEMS.Foundation.SearcherViewController<Organization, TSearcher> CreateSearcherViewController<TSearcher>()

where TSearcher : ISearcher, new()

{

LOC.CEMS.Foundation.SearcherViewController<Organization, TSearcher> svc =              WorkItem.Items.AddNew<LOC.CEMS.Foundation.SearcherViewController<Organization, TSearcher>>();

      svc.SetSearchResultsViewId(AssignmentViewId);

      svc.SetSearchViewId(SearcherViewId);

      mSearcherViewController = svc;

           

      return svc;

}

 

#endregion



Posted By: orcities
Date Posted: 08-Jan-2008 at 10:06am
One addtion: (Also in the tab controller) Configure Context Core

//Searcher

CreateContactGridContext();

pContext.AssignmentViewId = AssignmentViewId;//Constants.WorkspaceNames.SearchResultsViewSmartPartPlaceholder;

SearcherViewController.CreateSearcherViews(AssignmentBindingSource, GlobalService.EntityManager);



Posted By: Bill Jensen
Date Posted: 08-Jan-2008 at 11:43am

I'm not sure I completely follow your structure, but I'm guessing:

1.  You want two tabs, each displaying a FourPanelView.
 
2.  Each FourPanelView will will display a Searcher, a SearchResults Grid and two other views.
 
Each instance of a view to be displayed must be created with a unique ViewId.  The usual way to do this is to have the context of the containing view (one of the FourPanelView instances in this case) create a unique Id by combining its ViewId with a substring ("_Searcher", "_Assignment", etc.), then pass this to ViewFactory.AddNew<>(). 
 
Does FourPanelViewContext provide unique names?  Are you creating the Searcher and Assignment views and adding them to the workitem with the these unique ViewIds?
 
Bill J. 


Posted By: orcities
Date Posted: 08-Jan-2008 at 11:49am
Each does have unique Id's. I trace them back to the actually creation of the search control and it show the unique Id for each. But, the control does not display.


Posted By: DeLight
Date Posted: 11-Jan-2008 at 12:29pm
as for me I completely refused this Searchers, SearcherControllers, Views and so on. they just make the jogic more complicated and harder to maintain and understand.
 
my simple solution is:
1. create searcher view. simple AppView not having the ControlBindingManager and so on. but this view can have access to MainBindingSource and EntityManager through it's Presenter (see the example).
2. put all your textboxes, dropdowns, buttons to this view.
3. in your search button click handler just create your Query and refresh objects in your MainBindingSource.
4. that is all.
 
of course, this is not "the CAB way" from some points of view. but you are not struggling with this Searchers-logic. you are not messing your page controllers. you can have different searcher views and switch them easily in your page controller. think about it.
 
how to get your MainBindingSource:

public class NewBasicAppViewPresenter : AppViewPresenter<IAppView>

{

protected override void OnViewContextSet()

{

base.OnViewContextSet();

GetMainBindingSource();

}

#region MainBindingSource

private void GetMainBindingSource()

{

EntityBindingSource ebs = CabFns.GetMainBindingSource(WorkItem) as EntityBindingSource;

if (ebs != null)

{

this.mainBindingSource = ebs;

this.entityManager = ebs.EntityManager;

this.persistenceManager = entityManager.PersistenceManager;

}

}

private EntityBindingSource mainBindingSource;

public EntityBindingSource MainBindingSource

{

get

{

return mainBindingSource;

}

}

private IEntityManager entityManager;

public IEntityManager EntityManager

{

get

{

return entityManager;

}

}

private PersistenceManager persistenceManager;

public PersistenceManager PersistenceManager

{

get

{

return persistenceManager;

}

}

#endregion

}

 
this class is replacement for BasicAppViewPresenter.


-------------



Print Page | Close Window