Pages

Monday, May 27, 2013

Trigger Select All Checkbox Click in XPage view panels in XPages


This post shows the method through which the select all button that you would enable on a Xpage view panel can be programatically clicked.

I found need for a scenario in which I would require the document ids of all documents that are being displayed on a Xpage view in a browser. Eventually the simplest userfrinedly/user interactive mechanism that I was able to think about was the native select all feature available with the XPage view controls in Lotus Notes.

It took me quite a while to understand the usage though, It was quite tricky and tough but not any more :)
Following is the code fragment that allowed me to do this silly stuff

var viewPanelContainer=document.getElementById("ViewPanelContainer");

//-- Following line of code has been commented and the forth comming lines, second and third respectively
//have been introduced to bypass a IE bug related to the HTMLNode.getElementsByClassName command in javascript
//var selectAllCheckBox=viewPanelContainer.getElementsByClassName("xspCheckBoxViewColumnHeader")[0];
var selectAllCheckBoxes=getElementsByClassName(viewPanelContainer, "xspCheckBoxViewColumnHeader");
var selectAllCheckBox=selectAllCheckBoxes[0];
//-- End of block highlighting the work around for an IE bug


selectAllCheckBox.click(); //dispatchEvent("click");

Here I am using a function named as getElementsByClassName. The function is available in the blog, you can simply search for the same using the name itself or use any other method that you have. This is essential for the code to work in the tremendously awesome Internet explorer crap.

For all other poor browsers out there, they are in capable of making my life difficult and hence a simple object.getElementsByClassName will work on them

Hope this helps :)

Dojo Toolbar related tips and tricks in XPages

A while ago I was working on creating a tool bar for one of my Xpages. I was able to find a lot of reliable resources on the internet. It did take me a lot of time to understand and build my own toolbar though.

In summary my understanding is you may have to use all or few of the following dojo.require attributes in your page


dojo.require("dojo.parser");
dojo.require("dijit.form.Button");
dojo.require("dijit.Toolbar");
dojo.require("dijit.Tooltip");
dojo.require("dijit.ToolbarSeparator");

I also found that I was using the code line "var djConfig = { baseScriptUri : "js/dojo/",parseOnLoad : true };"
I am not sure if I had used the djConfig variable any where in my program to construct the tool. I guess it automatically loads with Xpages. If not - what stops you from a copy & paste :)

! guess I copy codes blindly at times lol.

Again I wanted this to be visible to the entire XPage and hence I used a "xp:scriptBlock" tag to define them

Later I copied code from the standard examples about dojo toolbar available on the web and modified it to suit my requirements
This sure is a lot of code. Just skip or delete the code fragments that might not be of interest to you.

Now I have acquired a decent tool bar when I preview the page on the browser. Which looks like the following.

<div id="toolbar" style='display:none;position:fixed;_position:absolute;
top:0;_top:expression(eval(document.body.scrollTop));
left:0;_left:expression(eval(document.body.scrollLeft));'>
<div id="toolbar1" dojoType="dijit.Toolbar">
<div dojoType="dijit.form.Button" id="toolbar1_Home"
iconClass="iconHome" showLabel="false">
Home
</div>
<span id="span6" dojoType="dijit.Tooltip" connectId="toolbar1_Home">
Home
</span>
<span data-dojo-type="dijit.ToolbarSeparator"></span>
<div dojoType="dijit.form.Button" id="toolbar1_ExportAll"
iconClass="iconExportAll" showLabel="true">
Export All
</div>
<span id="slides_tip" dojoType="dijit.Tooltip" connectId="toolbar1_ExportAll">
Export all data to Excel Sheet
</span>
<span data-dojo-type="dijit.ToolbarSeparator"></span>

<!-- div dojoType="dijit.form.Button" id="toolbar1_ExportSelected"
iconClass="iconExportSelected" showLabel="true">
Export Selected
</div>
<span id="fs_tip" dojoType="dijit.Tooltip" connectId="toolbar1_ExportSelected">
Export
selected documents to Excel Sheet
</span>

<span data-dojo-type="dijit.ToolbarSeparator"></span-->


<div dojoType="dijit.form.Button" id="toolbar1_PrintPage"
iconClass="iconPrintPage" showLabel="true">
Print
</div>

<span id="thumb_tip" dojoType="dijit.Tooltip" connectId="toolbar1_PrintPage">
Print the page as you see it
</span>
<span data-dojo-type="dijit.ToolbarSeparator"></span>

<div dojoType="dijit.form.Button" id="toolbar1_PrintAll"
iconClass="iconPrintAll" showLabel="true">
Preview All
</div>

<span id="span2" dojoType="dijit.Tooltip" connectId="toolbar1_PrintAll">
Preview all documents
</span>
<span data-dojo-type="dijit.ToolbarSeparator"></span>

<div dojoType="dijit.form.Button" id="toolbar1_PrintSelected"
iconClass="iconPrintSelected" showLabel="true">
Preview Selected
</div>

<span id="span1" dojoType="dijit.Tooltip" connectId="toolbar1_PrintSelected">
Preview selected documents
</span>

<span data-dojo-type="dijit.ToolbarSeparator"></span>

<div dojoType="dijit.form.Button" id="toolbar1_SearchField"
iconClass="" showLabel="true">
<xp:inputText style="width:222.0px" id="SearchContent">
</xp:inputText>
</div>
<div dojoType="dijit.form.Button" id="toolbar1_SearchButton"
iconClass="iconSearchButton" showLabel="false">
Search Image
</div>

<span id="span4" dojoType="dijit.Tooltip" connectId="toolbar1_SearchButton">
Search
</span>

<div dojoType="dijit.form.Button" id="toolbar1_HighlightButton"
iconClass="iconHighlightButton" showLabel="false">
Highlight Matches
</div>

<span id="span3" dojoType="dijit.Tooltip" connectId="toolbar1_HighlightButton">
Highlight
matches without searching
</span>

<div dojoType="dijit.form.Button" id="toolbar1_AdvSearchButton"
iconClass="iconAdvancedSearch" showLabel="false">
Advanced Search
</div>

<span id="span5" dojoType="dijit.Tooltip" connectId="toolbar1_AdvSearchButton">
Advanced
Searching Options
</span>

<span data-dojo-type="dijit.ToolbarSeparator"></span>
<div dojoType="dijit.form.Button" id="div1" iconClass=""
showLabel="true">
<xp:label value="Show " id="label3"></xp:label>
<xp:comboBox style="width:80.0px" defaultValue="30"
id="docsToDisplay">
<xp:selectItem itemLabel="30 Docs" itemValue="30">
</xp:selectItem>
<xp:selectItem itemLabel="50 Docs" itemValue="50">
</xp:selectItem>
<xp:selectItem itemLabel="100 Docs" itemValue="100">
</xp:selectItem>
<xp:selectItem itemLabel="200 Docs" itemValue="200">
</xp:selectItem>
<xp:selectItem itemLabel="1000 Docs" itemValue="1000">
</xp:selectItem>
<xp:eventHandler event="onchange" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:var searchViewGrid:com.ibm.xsp.component.xp.XspViewPanel=getComponent("searchViewPanel");
var docsToDisplay=getComponent("docsToDisplay").getValue();
var docToDispInt=java.lang.Integer.parseInt(docsToDisplay)
searchViewGrid.setRows(docToDispInt)}]]></xp:this.action>
</xp:eventHandler>
</xp:comboBox>
</div>
</div>
</div>

Its a lot of code. Atleast I got a nice looking tool bar like the following on my screen now.



Now take a closer look at the parent tag that I have defined for the tool bar. The style that is being computed/defined here helps the tool bar stay on top of the page irrespective of the page scroll

I dont know whether this method is recommended or not but, it servers the purpose. So if you find/know of a better way to do this please do let me know of the same.

Here the various icon classes that I have used here are responsible for the nice icons that are being displayed on the tool bar. So mark sure that you define your styles properly. Following is one such example of the associated style sheet

Our net stop is to see how to define an onclick event for our nice tool bar buttons here. Hi hi what did you expect. On click event related activites needs to be explicity defined through code and its not a simple onclick event definition. Following is the way to do it.

It would seem a little complicated, but its easy to understand. Following screen shot shows how I defined onclick events for the toolbar buttons along with how I defined the functions that were associated with the onclick events

Hope this helps :)


Monday, May 13, 2013

GetElementsBYClassName bug in IE

A while ago I was working with a checkBoxElement.click() type of function in which I had my client side javascript code identify the checkBoxElement through a HTMLNode.getElementsByClassName('myClassName') method.

This worked like charm with Chrome ( Chrome is the best :), unfortunately as expected this one had issues with the great Internet Explorer.

Eventually I had to scan through the web and with little effort I found the following nice function

function getElementsByClassName(node, classname) {
/* function obtained, modified and reused from
http://stackoverflow.com/questions/7410949/javascript-document-getelementsbyclassname-compatibility-with-ie
*/
var objectCollection = [];
        var re = new RegExp('(^| )'+classname+'( |$)');
        var els = node.getElementsByTagName("*");
        for(var i=0,j=els.length; i<j; i++)
            if(re.test(els[i].className))objectCollection.push(els[i]);
            return objectCollection;
        }

This worked well across both Chrome and IE. I am relieved :)

Hope this helps :)

Thursday, May 2, 2013

Function to bring focus to a html field element


function focusField(field) {
var myField;
if (typeof field==='string')
myField=document.getElementById(field);
else if (typeof field=='undefined')
return;
else myField=field;

window.setTimeout(function ()
    {
myField.focus();
myField.select();
}, 0);
}

Thursday, April 25, 2013

Search issues in XPages #1 - Dont forget to Create FTIndex in replicas manually

I have been working with XPages searches for a long time. It has been a while since I have worked with XPages and I was almost happy to get my hands on it again. I had to create a search feature that would help my clients perform a decent search.

Since they were ok with performing an FTIndex on the application, XPage searches was a nice option that occured to me.

To my frustration, proving that I got a little rusty with XPages, it took me 4 hours to get this search feature complete. I was bombarded with errors and for some reason, my search was not working the way I expected it to work.

Following are the summary of the issues that took me time to identify and fix

#1. Enable "Display Xpage runtime error page" in the XPages tab in "Application Properties". Else you would end up debugging for a long time

#2. My XPage's view control lost its data source referance and was showing a 'red X' in the application navigator which I missed to notice oweing to large number of design elements.

#3. Check source code pane, now and then to find if there are any errors being displayed. It will exist there with out any warning and you would not notice it on the design pane of the XPage

#4. Enable FTIndex inorder to work with the native search feature available with XPages

#5. Be warned, in case of clustered server, were replicas of databases from multiple servers are used to render a webpage. Because, FTIndex dont ret replicated. They need to be enabled and updated across replicas separately.

My search worked like charm after I rediscovered all of these items again :(

Wednesday, April 24, 2013

StartKey in View Url

I was working with StartKey argument in a view's url to help enable a search feature.

It was a headache. For some reason my startKey argrment was completely ignored by the browser.

EOD I found the following,

1. The first column in the view should show only simple text values. Date values with "/"s and other values with special characters are a head ache.
2. This wont work properly with views containing their first column as a hidden column
3. Your first column must be sorted for this argument to work.

I am not sure whether all of these are true or not. But its my understanding as per my experimentations so far.

Friday, March 8, 2013

A nice data recovery/undelete software - RECUVA

I recently got into a scenario, which had cost me my data archives containing data for almost a couple of years now. The exitement was great and this happened at a really very good time. Some one from holland and another one from Phillipenes where going to give me hollaphino problems and this happened just to same my sorry face. :)

And to add to my luck I knew  a few really good administrators who helped me a lot speaking about policy and **** that denies permissions for them to help me for an other 48 hours. And to add to my luck.... ok I guess you woud have already admitted to the fact that I am a really happy corporate fellow by now.
All this good life and sweet mares went away when I had to find "Recuva" and download it.

Are these guys crazy. They helped me find a file which I lot a couple of days ago. How dare they over take my admin guys. My admin guys are now wary cos of this and what to beat the **** of this one. What can a silly fellow like me do to save it. I had to give them a copy of this software.

My point is download the tool in the following website and see it for your self. :) It really works and it is free

http://www.piriform.com/recuva//download/standard

Saturday, February 9, 2013

Change native lotus notes database display format - view index on top and view in bottom

Every Lotus Notes Professional would be aware of the way lotus domino databases would be displayed on the notes client if no custom framet has been configured, It would be something like the following.

I just messed up the view names for personal reasons. So I think I make sense here. View index would be on the left margin and the view being displayed or selected will be displayed ont the right margin.

But did you ever know that we have an option to change that to the following silly format :)

Believe me I did not take two different screen shots and place them together. This is a screen shot as it is from the notes client. Yes view index is on top and the view being displayed or selected will be displayed in the bottom pane like a preview pane and yes you can have a separate preview pane for the view as well.

Its just that your display will be messed up and will be ackward. I sont recollect a scenario where this would be of advantage as far as lotus notes client applications are concerned. Atleast, I now know that I have such an option and can do it. May be I would use it to statle someone in the future hi hi :)

Yes I dream a lot :)

By the way, as far as I know you need to use the following @commands to get this done.

@Command([ViewBelowFolders])

and to get the display back to normal, you can use the following command

@Command([ViewBesideFolders])


Thursday, January 31, 2013

Fixed header for a html page

I was recently working with an application in which users requested for a fixed header that would not move  with the web page as its users scroll left or right.

I went through a bunch of options  to do it and every attempt I have made in the past with similar requests were kind of close and I had to include the usage of either quick javascrit functions that runs with a specified interval or I had to use the tag named "<!doctype>" and end up screwing my happiness with thanks to the different versions of the beautiful internet explorer.

I dont remember where I got the following stuff, but I really though that using "expression" with css is a no brainer. I also remember words from certain geeks advicing not to rely on them.

May be I dont understand the geeks yet, cos this 'expression' stuff with css seems to be good. Following is what I am taking about

<div style="left: 0px; left: expression(eval(document.body.scrollLeft)); position: fixed; top: 0px; top: expression(eval(document.body.scrollTop));">
My header contents </div>


I never knew that I had to use expression with eval of something. kriss... Thats some trick that I got to know better and remember. After all it makes life easier. Plus, this still has a few issues with the great internet explorer.Advanced users will eventually never use IE so better find a different browser to always work with.

On top of it, this code, I mean the usage of Expression keyword with Eval keyword is a trouble that you have to go through for IE alone. Because, "position:fixed" alone would do the work in Firefox and Chrome.


Thursday, January 17, 2013

List all ODBC Connections mapped with Lotus Notes using Lotusscript

A while ago I was given a very nice job of finding why a lotus script agent was not able to communicate with a DB2 server. And the nice stupid part about that is I never had acess to even view the log files of the server where the issue occurs. It was kind of frustrating for a while to understand/find the source of the issue with virtually no resources. It was that I was thinking about the most basic of the scenarios like, network problems, lan cable issues etc etc,

So eventually I just wanted to know if there is a way to list down the kind of connections that are prevalent with a lotus domino server and ended up discovering the following. Again I just discovered if for myself. It was always able on the innernet some how of the other.:)

The following code gives you a message box with something like,
 "The usable connections are file, notes, odbc2, oledb"

Atleast this is what I got. Evidently db2 was missing in the list for me and hurray, administrators found it at last that db2 was not mapped properly with the lotusdomino servers after looking at the proof . What ever that means. :P

Dim session As New LCSession
 Dim conName As String
 Dim text_str As String
' list the connectors available
' the parameters for connector code, identity flags, and
' identity names are optional and omitted in this example
 Call session.ListConnector(LCLIST_FIRST, conName)
 text_str = conName
 While session.ListConnector(LCLIST_NEXT, conName)
  text_str = text_str + ", " + conName
 Wend
 Msgbox "The usable Connectors are " & text_str