XPages SSJS add options to combo - xpages

In SSJS I'm looping through document in a view and I want to add a new option to a hidden combo for each document and once finished then show that hidden combo.
I've tried building an array with value|string and adding that to the getComponent("apm").setValue(myArray), but no luck and how do I grab the combo and make it visible because dojo.byId("#{id:apm}").setRendered(true); gives error about dojo not found, so do I need to include something?
Any ideas?

Add your array to a viewScope var.
In your combo, add a formula value and point it to the viewScope.
After your array is built make sure the combo is refreshed. You can set the rendered property based on whether or not your viewScope var exists.

Related

Select All checkbox lotus xpages

I'm working on an Xpages application on which I have a view control.
I tried to put a checkbox in the column header to select all of the check boxes in the view.
The problem is when I go to another page from the view, its lines are not checked and the selection is made only on the visible page.
So, I want to be able to select all the rows in all the pages of the view, this without the selection disappears when switching from one page to another of the view.
There are couple of problems with views and selections.
First of all, pager actions to move between pages does not process 'select all rows' data because it is enabled to use partial execution by default. If you put partialExecute="false" into your pager, you will see that 'select all rows' checkbox will be maintained between pages.
However, if you have a checkbox on a column and the columnHeader, the component maintains a selectedIds array in the back-end. Unfortunately, this array holds only visible selections. Because the array is maintained by the viewPanel component, which is not aware of the list of data entries that are not shown.
Also, checkbox implementation does not provide any even mechanism where you can grab selections on the back-end to cache them between pages.
To determine select all checkbox can be doable with a little trick. Assuming you are using all default styles;
<xp:inputHidden
id="inputAllSelected"
value="#{viewScope.allSelected}"
defaultValue="false"></xp:inputHidden>
<xp:scriptBlock
id="scriptBlock1">
<xp:this.value><![CDATA[
function getSelectAllCheckbox() {
return dojo.query("input.xspCheckBoxViewColumnHeader")[0];
}
function toggleSelectAll(){
dojo.byId("#{id:inputAllSelected}").value=getSelectAllCheckbox().checked;
}
dojo.addOnLoad(function() {
dojo.connect(getSelectAllCheckbox(), "onchange", toggleSelectAll);
});
]]></xp:this.value>
</xp:scriptBlock>
To cache checkboxes between pages, you would implement your own checkboxes by using custom columns. I recommend using a data table component to get more flexibility.

Filter Values in ChangeContentType Control

I am using the SharePoint:ChangeContentType control (which renders as a DropDownList in New/Edit modes). I need to manipulate the values that are present in the rendered DropDownList in the CodeBehind. I can't manipulate them with JavaScript/jQuery because I will get a ViewState exception.
I can get a reference to the ChangeContentType control but can't cast it as a DropDownList and therefore I can't get a refernce to the items in it in order to add/remove stuff.
Any ideas?
How to find ContentTypeChoice control (DropDownList) in SharePoint:ChangeContentType control:
DropDownList dropDownList = (DropDownList) control.TemplateContainer.FindControl("ContentTypeChoice");
ContentTypeChoice control gets populated during page load event.

Action Button works differently if added to the DataView

I have a button that calls a Dialog that has a combo box bound to a sessionScope variable. The combo box contains a list of form names that I use to then call an XPage to create a new document. The first value in the forms list is "" so the user needs to select a value. I have a button with the onClick event of:
var c = getComponent("CreateDocDialog");
sessionScope.put("ssSelectedForm","")
c.show();
I have the button and dialog on a customControl with a repeatControl and when the button to open the dialog is clicked the ssSelectedForm is null and the current value of the combo is blank, which is exactly what I want it to be. However, if I add the same button and dialog to a customControl with a dataView control the dialog displays but ssSelectedForm is not null so the combo box displays the last value of ssSelected. I have placed the button outside the dataView, in several of the facets on the dataview, but all with the same results.
Very confusing.
Bill,
I am going to answer the same as my comment since I am pretty confident about what I said.
Go ahead and change the scope from sessionScope to viewScope. I had a similar issue once, and I 'fixed' it by clearing out the sessionScope variable after I used it. This worked, but I realized that it was not necessary, and that by changing to viewScope the lifecycle will be shorter and there was no need to clear out the value when I was done with it.
I don't know why this fails when added to the data view, but if this fixes it that would be all that matters.

viewpanel selections being unselected on dialog box show

I have an extension pages dialog box on the same page as a viewpanel that has check boxes enabled. If I check some check boxes then show the dialog box, the selections in the view panel become unselected. Is anyone else seeing this?
I have the same issue and it looks like we're trying to do the same thing. I plan to add the selected IDs to a sessionScope, update their values, then remove the sessionScope.
I found this one, so I'll update here to see if it works: get the unid of selected documents and save to scoped variable
UPDATE:
I got it to work by setting a sessionScope variable for the selected IDs, as in the above example:
sessionScope.put("SelectedIds", getComponent("viewPanel1").getSelectedIds());
In the SSJS script, I changed the code to read the sessionScope array instead of the viewPanel's selections.
Fortunately, the IDs are very small (3 characters), so if there are a lot of documents, it should be ok.
Good luck!

Xpages - How to save values to list box that have been entered by client side javascript

I have a list box that I am adding and removing items with client side javascript. The issue is that these new values are not being saved to the list box(binded to field). The only value that comes back is the original one that was set in list box. The values are all there on the client since I can loop through the array. How can I get these values to replace the value that is currently there?
By default the listbox have a validator that you may not see during save, (you need to add error controls to see it) and the validator do not accept new values added using CSJS
If you set disableValidators="true" in the listbox control you suppress the validator and the save works fine. you also need to select the entries in the listbox using CSJS before you save,
Credits goes to Jesse Gallagher
Thomas
In the List Box properties, you must to set mutiple = true

Resources