Catching the Page Number of a Pager Being Clicked - xpages

It is possible to add an onClientLoad eventHandler to a viewPanel:
https://xcellerant.net/2013/01/14/viewpanel_onclientload
Clicking a Pager results in the onClientLoad being fired.
Question: is it possible to catch the Page Number of the Pager being clicked?

Add an on click event to every page number within pager in XPage's onClientLoad CSJS code.
Use dojo.query to get all a-tags within pager:
dojo.query('[id$=pagerWithClickEvents] a').forEach(function(entry) {
entry.addEventListener("click", function() {
alert(this.innerHTML);
});
});
This XPage is a working example:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view
xmlns:xp="http://www.ibm.com/xsp/core">
<xp:viewPanel
rows="3"
value="#{view1}"
id="viewPanel1">
<xp:this.facets>
<xp:pager
partialRefresh="true"
layout="Previous Group Next"
xp:key="headerPager"
id="pagerWithClickEvents">
</xp:pager>
</xp:this.facets>
<xp:this.data>
<xp:dominoView
var="view1"
databaseName="names.nsf"
viewName="People">
</xp:dominoView>
</xp:this.data>
<xp:viewColumn
columnName="$17"
id="viewColumn1">
<xp:viewColumnHeader
value="Name"
id="viewColumnHeader1">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn
columnName="$16"
id="viewColumn4">
<xp:viewColumnHeader
value="E-Mail"
id="viewColumnHeader4">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:eventHandler
event="onClientLoad"
submit="false">
<xp:this.script><![CDATA[
dojo.query('[id$=pagerWithClickEvents] a').forEach(function(entry) {
entry.addEventListener("click", function() {
alert(this.innerHTML);
});
});
]]></xp:this.script>
</xp:eventHandler>
</xp:viewPanel>
</xp:view>

Related

Get selected documents from a view and save as separate document

I am trying to get selected documents from a view and save as separate documents
Here is the design of the xpage
A combo box on the top, a view with check box (this view is used for selection), a button for save the selection values from the view and the combo box. Also there will another view which will display the saved values.
From this post, I can get the unid of selected documents and save to view scope variable. The add button can save the selected value from the combo box and the view and show the result in another view.
However, if I choose more than one value in the view and click save, it saves all values in one document. So I try to use for loop to loop through the selected values in view and save, it still saves one value only in one document.
<xp:table id="table1a">
<xp:tr>
<xp:td id="table1">
<xp:comboBox id="comboBox1"
dojoType="dijit.form.ComboBox" style="width:250.0px"
value="#{document1.Category}">
<xp:selectItems id="selectItems3">
<xp:this.value><![CDATA[#{javascript:var SetFirstValueBlank = #Text("");
return SetFirstValueBlank;
}]]></xp:this.value>
</xp:selectItems>
<xp:selectItems id="selectItems4">
<xp:this.value><![CDATA[#{javascript:#Unique(#DbColumn(#DbName(), "CategoryListView", 1));}]]></xp:this.value>
</xp:selectItems>
<xp:eventHandler event="onchange" submit="true"
refreshMode="partial" refreshId="table1a">
</xp:eventHandler>
</xp:comboBox>
<xp:text escape="true" id="computedField1">
</xp:text>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td>
<xp:viewPanel rows="10" id="viewPanel1" var="rowData">
<xp:this.data>
<xp:dominoView var="view1"
viewName="hListView">
</xp:dominoView>
</xp:this.data>
<xp:viewColumn columnName="ItemName"
id="viewColumn1" style="background-color:rgb(255,255,255)"
showCheckbox="true">
<xp:viewColumnHeader value="Item Name"
id="viewColumnHeader1" rendered="false">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:this.facets>
<xp:pager partialRefresh="true"
layout="Previous Group Next" xp:key="footerPager" id="pager2">
</xp:pager>
</xp:this.facets>
</xp:viewPanel>
<xp:br></xp:br>
<xp:button value="Add" id="button1"
style="height:35.0px">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:var Category = getComponent("comboBox1").getValue();
var viewPanel=getComponent("viewPanel1");
var docIDArray=viewPanel.getSelectedIds();
var unidArray = new Array();
for(i=0; i < docIDArray.length; i++) {
var unid=database.getDocumentByID(docIDArray[i]).getUniversalID();
unidArray.push(unid);
}
viewScope.put("unidArray", #Implode(unidArray, ","));
for(var i=0; i< unidArray.length;i++ )
{
document1.replaceItemValue("ItemName", unidArray[i]);
document1.save();
}
}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:viewPanel rows="6" id="viewPanel2">
<xp:this.data>
<xp:dominoView var="view2" viewName="CategoryItemView">
<xp:this.categoryFilter><![CDATA[#{javascript:getComponent("comboBox1").getValue();}]]></xp:this.categoryFilter>
</xp:dominoView>
</xp:this.data>
<xp:this.rendered><![CDATA[#{javascript:var value = getComponent("comboBox1").getValue();
if(value =="" || value == null)
{
return false;
}
else
{
return true;
}}]]></xp:this.rendered><xp:viewColumn id="viewColumn4" columnName="Category" rendered="false">
<xp:this.facets>
<xp:viewColumnHeader xp:key="header" id="viewColumnHeader4" value="Category">
</xp:viewColumnHeader>
</xp:this.facets>
</xp:viewColumn>
<xp:viewColumn id="viewColumn3" columnName="$10">
<xp:this.facets>
<xp:viewColumnHeader xp:key="header" id="viewColumnHeader3" value="Category">
</xp:viewColumnHeader>
</xp:this.facets>
</xp:viewColumn>
<xp:viewColumn columnName="ItemName" id="viewColumn2">
<xp:viewColumnHeader value="Item" id="viewColumnHeader2">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:this.facets>
<xp:pager partialRefresh="true" layout="Previous Group Next" xp:key="footerPager" id="pager3">
</xp:pager>
</xp:this.facets></xp:viewPanel><xp:br></xp:br></xp:td>
</xp:tr>
</xp:table>
Would someone let me know how to save multiple values in separate documents please? Thank you.
(edit: some of previous content are removed)
I think I will focus on how to save multiple value as separate documents first because this part is quite important in the program, once I can save as separate documents, there will another function that needs the result to process.
I review the code, I think I will still use for loop but unfortunately, it still saves one document only.
I'm guessing the document1 object is bound to a on the XPage, which is only created when the XPage is opened. To cause your button to create multiple documents, the for loop needs to modified :
var oneOfMany : NotesXspDocument;
for(var i=0; i< unidArray.length;i++ )
{
oneOfMany = database.createDocument();
oneOfMany.replaceItemValue( "Category", document1.getItemValue("Category" ) );
oneOfMany.replaceItemValue("ItemName", unidArray[i]);
oneOfMany.replaceItemValue("form", "MyFormName" );
oneOfMany.save();
}
Because it no longer uses document1, this loop will need to populate the other items you need such as the form, for example MyFormName as in the example.

xpages viewpanel pager combined with search not defaulting to the first page once user used the pager to navigate to the second,third,fourth etc. page

I have a viewpanel that I am using the "Search in view results" feature. The view has a pager. The scoped variable that I use for the search is null initially and the user has an option to choose from a list to create a search. The initial null search brings back about 1000 records and the user can use a page selector to scroll through the entries if they wish. If the user chooses say page 5 and then creates a search, the pager headers show up but no search results. In order to see the search results the user has to manually click on "first", then the pager resets and the results of the search appear.
I saw a solution in ViewPanel filter by StartKeys...but pager don't Update. However, I cannot use getAllEntriesByKey because I am returning the results of a search not a filter.
Here is the code, stripped down to the basics. In my application the user can create a search with up to 4 terms.
Thanks,
---Lisa&
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:table>
<xp:tr>
<xp:td><xp:comboBox id="TeacherComboBox" value="#{viewScope.TeacherComboBox}">
<xp:selectItems id="selectItems9">
<xp:this.value><![CDATA[#{javascript:return ""}]]></xp:this.value>
</xp:selectItems>
<xp:selectItems id="selectItems10">
<xp:this.value><![CDATA[#{javascript:var dbName = session.getCurrentDatabase();
var view = ("CampusCodes");
var CampusList = #Unique(#DbColumn(dbName,view,1));
return CampusList}]]></xp:this.value>
</xp:selectItems>
</xp:comboBox></xp:td>
</xp:tr>
<xp:tr>
<xp:td><xp:button id="button14" styleClass="BlueButtonSmall" value="Apply Search">
<xp:eventHandler event="onclick"
submit="true" refreshMode="complete" id="eventHandler17">
<xp:this.action><![CDATA[#{javascript:viewScope.TeacherSearchFormula = null;
var TeacherSearchFormula = null;
var Campus = null;
if (!!viewScope.TeacherComboBox) {
Campus = '[CampusNum]' + ' CONTAINS ' + viewScope.TeacherComboBox;
};
if (!!Campus) {
TeacherSearchFormula = Campus;
};
if (!!TeacherSearchFormula) {
viewScope.TeacherSearchFormula = TeacherSearchFormula;
print("viewScope.TeacherSearchFormula = ",viewScope.TeacherSearchFormula);
viewScope.ErrorLabel4T = "Search did not return any teachers.";
} else {
var varAlert = "Please choose some filters."
var al = "alert('"+ varAlert +"')";
view.postScript(al);
}}]]></xp:this.action>
</xp:eventHandler>
</xp:button><xp:button id="button15" styleClass="BlueButtonSmall" value="Clear Search">
<xp:eventHandler event="onclick"
submit="true" refreshMode="complete" id="eventHandler19">
<xp:this.action><![CDATA[#{javascript:getComponent("TeacherComboBox").setValue("");
viewScope.TeacherSearchFormula = null;
viewScope.TeacherComboBox = null;
}]]></xp:this.action>
</xp:eventHandler>
</xp:button></xp:td>
</xp:tr>
<xp:tr>
<xp:td>
<xp:viewPanel rows="30" id="viewPanel1">
<xp:this.facets>
<xp:pager xp:key="headerPager" id="pager1"
for="viewPanel1" partialRefresh="true">
<xp:pagerControl type="First"
id="pagerControl1">
</xp:pagerControl>
<xp:pagerControl type="Next"
id="pagerControl2">
</xp:pagerControl>
<xp:pagerControl type="Group"
id="pagerControl3">
</xp:pagerControl>
<xp:pagerControl type="Previous"
id="pagerControl4">
</xp:pagerControl>
<xp:pagerControl type="Last"
id="pagerControl5">
</xp:pagerControl>
</xp:pager>
</xp:this.facets>
<xp:this.data>
<xp:dominoView var="view1"
viewName="NISDTeacher" sortColumn="$1"
search="#{javascript:viewScope.TeacherSearchFormula}">
</xp:dominoView>
</xp:this.data>
<xp:viewColumn columnName="CampusNum"
id="viewColumn1">
<xp:viewColumnHeader value="CampusNum"
id="viewColumnHeader1">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="$1" id="viewColumn2">
<xp:viewColumnHeader value="TeacherFull"
id="viewColumnHeader2">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="CampusName"
id="viewColumn3">
<xp:viewColumnHeader value="CampusName"
id="viewColumnHeader3">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="TeacherEnumber"
id="viewColumn4">
<xp:viewColumnHeader value="TeacherEnumber"
id="viewColumnHeader4">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="TeacherPTitle"
id="viewColumn5">
<xp:viewColumnHeader value="TeacherPTitle"
id="viewColumnHeader5">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="RatingText"
id="viewColumn6">
<xp:viewColumnHeader value="RatingText"
id="viewColumnHeader6">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="RatingNum"
id="viewColumn7">
<xp:viewColumnHeader value="RatingNum"
id="viewColumnHeader7">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="Comments"
id="viewColumn8">
<xp:viewColumnHeader value="Comments"
id="viewColumnHeader8">
</xp:viewColumnHeader>
</xp:viewColumn>
</xp:viewPanel></xp:td>
</xp:tr>
</xp:table></xp:view>

Viewpager not working when unitegallery is on same page

I would like to use a viewPanel and unitegallery on the same page.
When they are on the same page, the pager from the viewPanel doesn't seem to work anymore.
Only the first page from the viewPanel is displayed.
It's impossible to go to the next items in the view.
My example code :
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xc="http://www.ibm.com/xsp/custom"
xmlns:xp_1="http://www.ibm.com/xsp/coreex"
pageIcon="/Logo-6%2C17-x-6%2C17.png">
<xp:this.resources>
<xp:script src="/JQueryXSnippet.js" clientSide="true"></xp:script>
</xp:this.resources>
<script type='text/javascript'
src='../../demo.nsf/unitegallery/js/unitegallery.min.js'>
</script>
<link rel='stylesheet'
href='../../demo.nsf/unitegallery/css/unite-gallery.css'
type='text/css' />
<script type='text/javascript'
src='../../demo.nsf/unitegallery/themes/carousel/ug-theme-carousel.js'>
</script>
<xp:scriptBlock id="scriptBlock1">
<xp:this.value><![CDATA[
$(document).ready(
function() {
x$("#{id:gallery}").unitegallery({
gallery_theme: "carousel",
tile_width: 60, //tile width
tile_height: 60, //tile height
tile_enable_textpanel:true,
tile_textpanel_title_text_align: "left",
});
}
);
]]></xp:this.value>
</xp:scriptBlock>
<xp:this.data>
<xp:dominoView var="view4" viewName="country_extra_pictures"
keys="VBD200">
</xp:dominoView>
</xp:this.data>
<xp:br></xp:br>
<div id="gallery" style="display:none;">
<xp:repeat rows="100" var="pictureData" value="#{view4}" removeRepeat="true" id="additionalpictures">
<xp:image url="#{javascript:pictureData.getColumnValue('ThPicture');}"
alt="#{javascript:pictureData.getColumnValue('title')}">
<xp:this.attrs>
<xp:attr name="data-image" value="#{javascript:pictureData.getColumnValue('BigPicture')}">
</xp:attr>
</xp:this.attrs>
</xp:image>
</xp:repeat>
</div>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:viewPanel rows="11" id="viewPanel12" var="rowData" target="_self">
<xp:this.facets>
<xp:pager partialRefresh="true"
layout="Previous Separator Group Separator Next"
xp:key="headerPager" id="pager1">
<xp:this.rendered><![CDATA[#{javascript:getComponent("viewPanel12").getRowCount() > 10}]]></xp:this.rendered>
</xp:pager>
</xp:this.facets>
<xp:this.data>
<xp:dominoView var="view12" databaseName="product/spareparts.nsf" viewName="spareparts3"
keys="D200Current">
</xp:dominoView>
</xp:this.data>
<xp:viewColumn id="viewColumn18" columnName="spareProductPart">
<xp:this.facets>
<xp:viewColumnHeader
xp:key="header" id="viewColumnHeader18" sortable="false"
value="Product part">
</xp:viewColumnHeader>
</xp:this.facets>
</xp:viewColumn>
<xp:viewColumn id="viewColumn29" columnName="spareAsFrom">
<xp:this.facets>
<xp:viewColumnHeader
xp:key="header" id="viewColumnHeader29" value="As from">
</xp:viewColumnHeader>
</xp:this.facets>
</xp:viewColumn>
</xp:viewPanel>
</xp:view>
Just a guess as I don't know this plugin: it seems that the plugin changes the DOM of the view control so that the pager is not able to work with it anymore. This is a problem of several plugins that they change the original DOM significantly. You should exam the DOM (and compare it) with a debug tool from e.g. Chrome to watch the differences between the DOM without and with activated plugin.

xpages full text searching

I've been following Dave's Notesin9 video on full text searching.
My source code is:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
defaultLinkTarget="_blank">
<xp:br></xp:br>
<xp:inputText id="inputText1" value="#{requestScope.variant}"></xp:inputText>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:text escape="true" id="computedField1" value="#{javascript:requestScope.variant}"></xp:text>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:button id="button3" value="Search"><xp:eventHandler event="onclick" submit="true" refreshMode="complete" immediate="false" save="true"></xp:eventHandler></xp:button>
<xp:br></xp:br>
<xp:viewPanel id="viewPanel1" pageName="/p_form.xsp" rows="20">
<xp:this.facets>
<xp:pager partialRefresh="true" layout="Previous Group Next"
xp:key="headerPager" id="pager1" style="width:40.0px">
</xp:pager>
<xp:viewTitle xp:key="viewTitle" id="viewTitle1"
value="List of documents"
style="width:153.0px;background-color:rgb(64,128,128);color:rgb(255,255,0)">
</xp:viewTitle>
</xp:this.facets>
<xp:this.data>
<xp:dominoView var="view1" viewName="vijay"
search="#{javascript:requestScope.variant}">
</xp:dominoView>
</xp:this.data>
<xp:viewColumn columnName="name" id="viewColumn1"
showCheckbox="true" displayAs="link">
<xp:viewColumnHeader value="name" id="viewColumnHeader1"
style="background-color:rgb(192,192,192)">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="age" id="viewColumn2">
<xp:viewColumnHeader value="age" id="viewColumnHeader2"
style="background-color:rgb(192,192,192)">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="email" id="viewColumn3">
<xp:viewColumnHeader value="email" id="viewColumnHeader3"
style="background-color:rgb(192,192,192)">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn id="viewColumn4" style="width:89.0px"
displayAs="link" columnName="$6">
<xp:this.facets>
<xp:viewColumnHeader xp:key="header"
id="viewColumnHeader4" value="Attch">
</xp:viewColumnHeader>
</xp:this.facets>
</xp:viewColumn>
</xp:viewPanel>
<xp:button value="New Topic" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action>
<xp:openPage target="newDocument" name="/p_form.xsp"></xp:openPage>
</xp:this.action>
</xp:eventHandler>
</xp:button>
<xp:button value="Delete selected" id="button2">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action>
<xp:deleteSelectedDocuments view="viewPanel1"
message="Are you sure to delete it('em)?">
</xp:deleteSelectedDocuments>
</xp:this.action>
</xp:eventHandler>
</xp:button>
</xp:view>
here, included a textfield to input the search term,
computed field to view the queried term,
a button labelled search as a submit button.
Entered value in the textfield and
when i press the search button, i get error 500.
Where lies the mistake?
Pls help.
Naveen's almost certainly spot on, that the database is not full text indexed. Check the \data\IBM_TECHNICAL_SUPPORT folder on the server, for the latest modified file starting xpages_exc_###. This will give the full detailed error, including the stack trace. The XPages Log Reader project on OpenNTF can be used to view those files from a browser.
I'd recommend using sessionScope instead of requestScope for the search value. If you use requestScope, it's only available during that partial refresh. So when the user uses a pager or opens a document and goes back to the view, the requestScope variable is null again, so the search criteria are lost.

Show only Unread document current View?

anyone have a suggest to realize #Command([ViewShowOnlyUnread]) in XPages ViewPanel?
And is possibile realize the function "Next Unread" and "Previus Unread"?
Instead of binding the view panel to a standard view data source, try setting its value attribute to the following expression:
importPackage(com.ibm.xsp.model.domino);
var targetView = database.getView("Some View");
var unreadEntries = targetView.getAllUnreadEntries();
var unreadModel = new DominoViewEntryCollectionDataModel(unreadEntries);
return unreadModel;
The view panel should then behave exactly as it would if it were bound to a true data source, but only display the unread entries.
Excellent answer from Tim..
Here's other version with Repeat Controls -
<xp:repeat id="repeatUnreadEntries" var="viewEntry" indexVar="index" rows="30">
<xp:this.value><![CDATA[#{javascript: return database.getView('viewName').getAllUnreadEntries()}]]></xp:this.value>
<xp:this.facets>
<xp:panel id="repeatHeader" xp:key="header">
<xp:text disableTheme="true" escape="false">
<xp:this.value>
<![CDATA[<TABLE><THEAD><TH>Cell1</TH><TH>Cell2</TH></THEAD><TBODY>]]>
</xp:this.value>
</xp:text>
</xp:panel>
<xp:panel id="repeatFooter" xp:key="footer">
<xp:text disableTheme="true" escape="false">
<xp:this.value><![CDATA[</TBODY></TABLE>]]></xp:this.value>
</xp:text>
</xp:panel>
</xp:this.facets>
<TR>
<xp:repeat var="entryColVal" indexVar="colIndex" value="#{javascript:viewEntry.getColumnValues()}">
<TD>
<xp:text value="#{entryColVal}" />
</TD>
</xp:repeat>
</TR>
</xp:repeat>
The code provided by Tim Works if you set data and value attributes to view panel, like below.
<xp:viewPanel rows="30" id="viewPanel1">
<xp:this.facets>
<xp:pager partialRefresh="true" layout="Previous Group Next" xp:key="headerPager" id="pager1"></xp:pager>
</xp:this.facets>
<xp:this.data>
<xp:dominoView var="view1" viewName="vwSrc"></xp:dominoView>
</xp:this.data>
<xp:this.value><![CDATA[#{javascript:importPackage(com.ibm.xsp.model.domino);
var targetView = database.getView("vwSrc");
var unreadEntries = targetView.getAllUnreadEntries();
var unreadModel = new DominoViewEntryCollectionDataModel(unreadEntries);
return unreadModel();}]]></xp:this.value>
<xp:viewColumn columnName="col1" id="viewColumn1">
<xp:viewColumnHeader value="Column1" id="viewColumnHeader1"></xp:viewColumnHeader>
</xp:viewColumn>
</xp:viewPanel>

Resources