Accessing the datasource of the XPage from a Custom Control - custom-controls

I guess that I am really missing something on the datasource in a custom control. When I create the custom control I have no idea what the name of the datasource on the XPage is going to be. I have added a custom property to the custom control to pass using the Type com.ibm.xsp.domino.model.DominoDocumentData and the Method Binding Editor, and this sort of seems to work if the Custom Control does not contain Custom Controls. At which point either I am getting lost or the XPage/Custom Control binding is getting lost.
Here is what I am trying to do I have created a Tab Table using the Extension Library and have placedd it on a cc. I have set up several tabs on it. Because the amount of information on each tab is pretty extensive I thought I would create a custom control for each tab. Then I ask the Yes/No question on almost every line I created a ccYN custom control, plus a couple of other ones as well because they can be reused and simple bound to a different fieldName that I have set up in the cc Properties. I see where others have said that if the datasource is defined for the XPage that it is available to all of the cc's, the method above seems to work for the first level but deeper than that leaves me or the XPage really confused. I have searched the internet/read Mastering Xpages but am not much further ahead.

It has been a long drawn out process but I think I have it now. On the Custom Control create a Property definition with a type of com.ibm.xsp.model.ModelDataSource with an edit type of String and call it something say ccDataSource. Then bind the the ccDataSource to the datasource of the XPage that contains it when it is know using SSJS so say it is myDataSource.
If the Custome Control is contained in a custome control and the datasource needs to be passed through another level the the binding is compositeData.ccDatasource or ?? whatever the outer datasource Property definition for the Data Source is.
There might be a cleaner way of doing this but I have not found it.

Not sure if you're still looking for an answer, but you can use the data source of "currentDocument" in a custom control. This assumes that the custom control is in a panel with one document data source, or in an XPage with one document data source.

Related

Autoit getting the name of a control

I have a VB6 control (VSFlexGrid) that I would like to get the name of. I have a class and id to reference it by and I am able to focus it but I don't know how I am suppose to retrieve the name of the control. How would I do this in Autoit?
in form design mode the grid is given a name in the property window.
you can reference it by the Name given in code.
so select the grid in the form design view and press F4 - the (name) property will be something like VSFlexGrid1 or maybe myGrid or some such..
In code you can refer to it as VSFlexGrid1.Position or VSFlexGrid1.Rows or whatever of it's properties you need to work with.
You can do more exotic things like looping through the form controls collection and detecting if it is a VSFlexGrid type, but that may be more than you are looking for.

XPages - Bind Document Data Source in a embedded Custom Control

I created a custom control that is binded to a a Domino Document data source. I embedded it in a page so that I can display it in a Dojo dialog. It has 2 properties: dialogId and docId. The document data source's Document ID property is set to compositeData.docId. In the page, I set the docId property to a viewScope variable, that will be set when an entry in a view is clicked. What I want to accomplish is that the dialog will display the document that the current view entry (that was clicked) represents. But it seems that the compositeData.docId is not set on partial or even full refresh. Is there a way to do this that the custom control will be binded to the document? I need to have this binding so that I can easily do a server-side validation when I submit the dialog. Or if there is another way, can you also put it here? Thanks a lot!
set the datasource as the document, and then edit mode, then you have a place to compute the doc id, i usually compute the doc id to a viewScope, that i set when i click the item in the repeat control
More details here.
I would prefer the DocId to be transfered via the custom control parameters rather than a Scope variable. Using the Scope breaks the custom control design principle of being self contained. You can use the yourCC.PropertyMap to actually update a value, so the hand over of the parameter will work - of course your control then needs to be refreshed so the data source is recomputed. Hope that helps.

Bind various panaroma/pivot items using MVVM

could someone help me with design/understanding the problem: what I need to achieve is page with Panorama/Pivot control, where its items (panos/pivots) will be set via binding, using standard MVVM pattern. Problem is I need to have different content (different user controls) on each pano/pivot, that means If I define a panorama/pivot item template, I doom all of them to be alike, which is not what I want.
I found this question here already asked: Databound windows phone panorama with MVVM design but its still not clear to me. Many thanks.
If you have a dynamic page count on panorama/pivot you could use selector to choose what template is right according to your content.
Implementing DataTemplateSelector
Also, Data Binding Pivot to MVVM may help you too
You could add a dependency property to the user control that you want to use as a data template, a dependency property named "Type" for example and depending on that property you can change the layout of your user control (data template) - for example you could have multiple grids inside your user control and you could show and hide them depending on the type.

Using PhoneApplicationPage as a nested view container

In MVVM Light toolkit for Windows Phone, whenever I am to add a new MvvmLightView (WP) item, I end up with the template creating a PhoneApplicationPage for me.
What about cases, when I want to create a nested view, for example in case of a ListBox ItemTemplate view.
Before MVVM Light, every time I needed a view to separate markup to, I would have created a standard UserControl and that worked fine.
Should I only use MvvmLightView whenever creating a navigable pages?
The item template is a guidance, that produces some code for you. It is not, nor does it intend to be, the single way of creating views or sub views.
In the case you are mentioning, it is usual to create a user control hat is backed on its own view model. This sub-view view model is then included as a property in your main view model. To pass it to your sub-view (e.g. a user control) you bind this property to the user control's DataContext.
<ext:MyUserControl DataContext="{Binding MySubViewProperty}"/>
However, you do not need a separate view model, in some cases it is more appropriate to share the main view model. In this case you do not need to do the above binding, as it is do one implicitly. Also, when you are using the user control within an DataTemplate the templates DataContext is passed to the user control implicitly and you do not need the binding. In general you only need to set the data context when you want to bind to a property of the current context, or to another context.
MVVM is about freedom and MVVM Light about supporting the developer in using this freedom. All guidance are best practises and provide usually the easiest an/or most consistant way, but nothing stops you going down another route for a good reason. Especially the templates are just shortcuts that provide for one problem, but not for the general (meaning every) case.

How do I add a control at design time without using Drag 'n' Drop?

I'm attempting to create a Wizard type control in VB6 and have run into a stumbling block.
I'd like to allow users of the control to be able to add and manage CWizardPage(s) to the design time control using a property page.
The first approach I used was to add the Wizard pages to the OCX directly using a Collection, however I ran into two problems in that the Collection class is not persistable (and I couldn't find an easy way to make it so) and that VB6 seems very limited in it's ability to instantiate controls at run time - so it would seem to be a struggle to actually re-instantiate them.
My next thought was to just allow the users to draw the wizard pages at design time. This sort of works, however it's far too easy to draw one of the wizard pages inside another wizard page instead of inside the CWizardContainer.
So can anyone please tell me how to add controls to a form at design time without using drag 'n' drop?
You can dynamically add controls to a form or other container (such as a UserControl) using the Add method of the container's Controls collection. For example, to add a TextBox named myTextBox to a form called frmMyForm, you could do this:
frmMyForm.Controls.Add "VB.TextBox", "myTextBox"
Here is a snippet from the VB6 help file:
Add Method (Controls Collection)
Adds a control to the Controls
collection and returns a reference to
the control.
Syntax
object.Add (***ProgID, name, container*)**
The Add method syntax has these parts:
object (Required)
An object expression that evaluates to
an object in the Applies To list.
ProgID (Required)
A string that
identifies the control. The ProgID of
most controls can be determined by
viewing the Object Browser. The ProgID
is composed of the Library and Class
of the control. For example, the
CommandButton control's ProgID is
VB.CommandButton. In cases where the
ProgID differs from that shown in the
Object Browser, Visual Basic displays
an error message that contains the
correct ProgId.
name (Required)
A string that identifies the member of
the collection.
container (Optional)
An object reference that specifies a
container of the control. If not
specified or NULL, defaults to the
container to which the Controls
collection belongs. You can put a
control in any existing container
control (such as the Frame control) by
specifying this argument. A user
control or an ActiveX document can
also be a container.
...VB6 seems very limited in it's
ability to instantiate controls at run
time...
Nothing could be further from the truth. Instantiating controls at run time in VB6 is trivial.
At design time, set the Index
property of the control to 0. This
turns the control into a control
array.
At runtime, load new instances of the control as needed.
As an example, create new Standard EXE project drop a TextBox onto the form, set its Index to 0 and put the following in the Form_Load event:
Private Sub Form_Load()
Dim newIndex As Integer
newIndex = Text1.UBound + 1
Load Text1(newIndex)
Text1(newIndex).Top = Text1(newIndex - 1).Top + Text1(newIndex - 1).Height
Text1(newIndex).Visible = True
End Sub
I have worked on an application that regularly made many whole data entry screens dynamically based on the desired fields. It's verbose to specify the Top, Left, Width, and Height all the time. So, you usually have a "template" of the control and copy those settings to the additional one.

Resources