Pages

Wednesday, December 29, 2010

Grouping Radio Buttons inside Repeat Control in XPages

When you put a Radio button inside a repeat control in XPages and give it a group name as follows,

we explicitly assume that the radio buttons that get created as a result of the repeat control share the same  group name and behave in a the expected way. Ofcourse there is nothing wrong in expecting that. But its just that we miss a few points that are associated with the way XPages render them- so much for the documentations of XPages..... X(

To my amusement the following is what I experienced

I did panic a bit too but that is hidden :)
The fix that I got from the sources over the internet was to add the Skip Container attribute to the radio button tag.

Click the radio button and choosing its All Properties menu and specifying 1 against the skip containers attribute helped me get the normal functionality in a tricky way X(.

Well probably my words are confusing... Take a look into the following image...

Hope this helps :)

Wednesday, December 22, 2010

Issues with document.getElementById of computed fields in xpages

This is one of the most irritating issues that I encountered in XPages. Again XPages are not the ones to be blamed, it was me- did not understand how the elements got rendered on the browser.

The issue in short is that I was not able to retrieve or set value to a Computed Field on an XPage using client script

Say my field name on the XPage is "XPageEditBox"

now, document.getElementById("#{id:XPageEditBox}").value did not help me to get or set the values of the edit box.

This was because, I though that the edit box will be rendered as a html field and that was not the case. It was rendered as a span tag.


So the way to access the values is as follows,

var myValue=document.getElementById("#{id:XPageEditBox}").innerHTML to get and

document.getElementById("#{id:XPageEditBox}").innerHTML=myValue to set

Hope this helps :)

Friday, December 17, 2010

Controlling preview of views on the browser - $$ViewTemplateDefault

Though this has always been known, A few of my colleagues needed info on this. So just thought of sharing the same. Hope this helps some one who is looking for this :)

Create a form named "$$ViewTemplateDefault"  and key in a few text info as follows
Now when a view from the database is previewed this is how the following is a sample illustration of how they look on the client and the browser
On Client:
On Browser:

Hope this Helps :)

Thursday, December 16, 2010

Array Base Index and Base in Lotusscript (Option Base 0|1)

I happened to stumble upon the base index of arrays when a colleague of mine came up with a doubt in Base command in lotus script

It was interesting to find the following,

Create a couple of buttons and put the following fragments of code in each of them

option base 0
dim myArray[10] as string
msgbox cstr(lbound(myArray)) '--> this would prompt 0

This means now the array can contain 11 string values, where the index varies from 0 to 10

option base 1
dim myArray[10] as string
msgbox cstr(lbound(myArray)) '--> this would prompt 1

And this means the array can contain 10 string values, where the index varies from 1 to 10

Inference :

Option Base 1 in lotus script implies that the arrays will have a lower bound of 1 as is the case with Formula language

Extra Note :
In case of Java, an array of the following sort say,
String[] x= new String[10]

x shall hold 10 values with indices varying from 1 to 10

Hope this helps :)

Video: Using the XPages Extension Library Dojo Grid and REST Services Controls

Wednesday, December 15, 2010

User .jar files must be considered a design element



Monday, December 6, 2010

Get the handle of the document highlighted in a view

Inorder to obtain the handle of a document highlighted in a view, use the following property

caretNoteID$ = notesUIView.CaretNoteID


Though this is present all along, I never got to use it cos I never really put UIClasses to any good use because I was blinded by their limitations rather than their capability...


Had a tough time finding this one vhsssss.... oh....


Hope this helps some one :)

Wednesday, December 1, 2010

Get notes temporary directory path in lotusscript

Declare Function w32_OSGetSystemTempDirectory Lib "nnotes" Alias "OSGetSystemTempDirectory" ( Byval S As String) As Integer 
Declare Function mac_OSGetSystemTempDirectory Lib "NotesLib" Alias "OSGetSystemTempDirectory" ( Byval S As String) As Integer 
Declare Function linux_OSGetSystemTempDirectory Lib "libnotes.so" Alias "OSGetSystemTempDirectory" ( Byval S As String) As Integer 
Const ERR_UNSUPPORTED_PLATFORM = 20300 ' or other value you choose. 




Function GetNotesTempDirectory() As String 
' Returns the path of the temporary directory used by Notes. 
Dim session As New NotesSession 
Dim d As String * 256 
Dim s% 
Select Case session.Platform 
Case "Linux" 
s% = linux_OSGetSystemTempDirectory(d) 
Case "Macintosh" 
s% = mac_OSGetSystemTempDirectory(d) 
Case "Windows/32" 
s% = w32_OSGetSystemTempDirectory(d) 
Case Else 
Error ERR_UNSUPPORTED_PLATFORM, "In GetNotesTempDirectory, platform not supported: " & session.Platform 
End Select 
GetNotesTempDirectory = Left$(d, s%) 
End Function


Hmmm... this is a copy paste from moorthydaniel's blog... seemed to be a nice one...
So its my turn to share the same

God got to understand those lib stuffs... seems like a head ache :(

Hope this helps :)

Lotusscript code to get the mime content of an image

Function  getMimeofImage( imagePath As String,targetFilePath As String) As Boolean
'************************************************************************************************************ 
'@Purpose     :   To create mime equivalent of an image file in a text format and export the same to a target file
'************************************************************************************************************

'mark the flow of control moving inside the current function
getMimeofImage=False

'declare variables and objects necessary for further manipulation
Dim session As New notessession
Dim currDB As NotesDatabase
Dim tempDoc As NotesDocument
Dim stream As NotesStream
Dim mimeEntity As NotesMimeEntity
Dim imageSize As Long

'initiation
'handler errors in case of abrupt termination
On Error Goto mimeErrHandler

'set handle for the current database
Set currDb=session.CurrentDatabase
'create a temporary document
Set tempDoc=currDb.CreateDocument

'create a stream object
Set stream = session.CreateStream
If Not stream.Open(imagePath) Then
Error 1404, "Cannot open file " & imagePath & " for processing."
Exit Function
End If

imageSize = stream.Bytes

Set tempDoc=currDB.CreateDocument
Set mimeEntity = tempDoc.CreateMIMEEntity
If Right(Lcase(imagePath), 4) = ".gif" Then
Call mimeEntity.SetContentFromBytes(stream, "image/gif", ENC_NONE)
Else
Call mimeEntity.SetContentFromBytes(stream, "image/jpeg", ENC_NONE)
End If
Call mimeEntity.EncodeContent(ENC_BASE64)

Call stream.Close


Set stream=Nothing
Set stream=session.CreateStream
Call stream.Open(targetFilePath)
If stream.Bytes <> 0 Then
Call stream.Truncate
End If
' Call stream.WriteText()

Call stream.WriteText(|<?xml version='1.0'?><document xmlns='http://www.lotus.com/dxl' version='8.5' maintenanceversion='1.0' replicaid='652577AF00410F29' form='dxlManipulations'><noteinfo noteid='94e' unid='8F605FA904982F43652577EB00207375' sequence='1'><created><datetime>20101130T112427,09+0530</datetime></created><modified><datetime>20101130T112427,10+0530</datetime></modified><revised><datetime>20101130T112427,09+0530</datetime></revised><lastaccessed><datetime>20101130T112427,09+0530</datetime></lastaccessed><addedtofile><datetime>20101130T112427,09+0530</datetime></addedtofile></noteinfo><updatedby><name>CN=Karthikeyan A/O=Maargasystems</name></updatedby><item name='rt'><richtext><pardef id='1'/><par def='1'><picture width='183px' height='62px'><gif>|+mimeEntity.ContentAsText+|</gif></picture></par></richtext></item><item name='TestField'><text>3</text></item></document>|)
' Call stream.WriteText()

Call stream.Close

'mark the flow of control moving out of the current function
getMimeofImage=True
Exit Function
mimeErrHandler:
Print "Error ***" & Error & "*** occured on line ***" & Cstr(Erl) & "*** with error number ***"   _
& Cstr(Err) & "*** in Method ""CreateMIMEEntity"" "
Exit Function
End Function

Hope this helps :)

Lotusscript code to import dxl to current database

Function importDxl(dxlFilePath) As Boolean

'***********************************************************
'@Purpose : To import dxl into current database 
'@Author   : Karthikeyan A
 '@Note : The dxl file should contain the dxl that corresponds to a notes document in this case
'*********************************************************** 

'mark the flow of control moving into  the current function
importDxl=False

'declare all variables and objects necessary for further manipulation
Dim session As New NotesSession
Dim dbdir As NotesDbDirectory
Dim db As NotesDatabase
Dim stream As NotesStream
Dim importer As NotesDXLImporter

'handle errors in case of abrupt termination
On Error Goto errHandler

REM set handle for the current database
Set db = session.CurrentDatabase

'create a stream
Set stream = session.CreateStream

'open the dxl file to be imported
If Not stream.Open(dxlFilePath) Then
Msgbox "Cannot open " & dxlFilePath, , "Error"
Exit Function
End If
'if the file is empty then inform the same to the user and exit
If stream.Bytes = 0 Then
Msgbox "File did not exist or was empty", , dxlFilePath
Exit Function
End If

REM Import DXL into current database
Set importer = session.CreateDXLImporter
importer.ReplaceDBProperties = False
importer.ReplicaRequiredForReplaceOrUpdate = False
importer.ACLImportOption = DXLIMPORTOPTION_REPLACE_ELSE_IGNORE
importer.DesignImportOption = DXLIMPORTOPTION_REPLACE_ELSE_IGNORE
Call importer.Import(stream, db)

'close the current stream
Call stream.Close

'mark the flow of control moving out of  the current function
importDxl=True
Exit Function
'display the errors that resulted in abrupt termination
errHandler:
Print "Error ***" & Error & " occured on line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err)  & "*** while attempting to importDxl"
Msgbox "Error ***" & Error & " occured on line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err)  & "*** while attempting to importDxl"
Exit Function
End Function

Hope this helps:)

Lotusscript code to export dxl of a Notes document

Function exportDocDxl(sourceDoc As NotesDocument,targetFilePath As String) As Boolean
'***********************************************************
'@Purpose : To export the dxl of a database to the specified document
'@Author   : Karthikeyan A
'*********************************************************** 

'mark the flow of control getting inside the current function
exportDocDxl=False

'declare all variables and objects necessary for further manipulation
Dim session As New NotesSession
Dim db As NotesDatabase
Dim exporter As NotesDXLExporter
Dim opStream As NotesStream

'handle errors in case of abrupt termination
On Error Goto errHandler

'create a dxl exporter
Set exporter = session.CreateDXLExporter
'create a stream
Set opStream=session.CreateStream
'open the targetFilePath using the stream
If Not opStream.Open(targetFilePath) Then
Msgbox "Cannot open "& targetFilePath, , targetFilePath
Exit Function
End If
If opStream.Bytes <> 0 Then
Call opStream.Truncate
End If

'export the contents on the current database to the stream (i.e. the target file path)
Call opstream.WriteText(exporter.Export(sourceDoc))
'once the export is complete close the stream
Call opstream.Close

  'mark the flow of control moving out of  the current function
exportDocDxl=True
Exit Function
'display the errors that resulted in abrupt termination
errHandler:
Print "Error ***" & Error & " occured on line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err)  & "*** while attempting to export dxl of selected document"
Msgbox "Error ***" & Error & " occured on line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err)  & "*** while attempting to export dxl of selected document"
Exit Function
End Function


Hope this helps:)

Lotusscript code to export dxl of a database

Function exportDBDxl(sourceDB As NotesDatabase,targetFilePath As String) As Boolean
 '***********************************************************
 '@Purpose : To export the dxl of a database to the specified location
 '@Author   : Karthikeyan A
 '*********************************************************** 

'mark the flow of control getting inside the current function
exportDBDxl=False

'declare all variables and objects necessary for further manipulation
Dim session As New NotesSession
Dim db As NotesDatabase
Dim exporter As NotesDXLExporter
Dim opStream As NotesStream

'handle errors in case of abrupt termination
On Error Goto errHandler

'create a dxl exporter
Set exporter = session.CreateDXLExporter
'create a stream
Set opStream=session.CreateStream
'open the targetFilePath using the stream
Call opStream.Open(targetFilePath)
'export the contents on the current database to the stream (i.e. the target file path)
Call opstream.WriteText(exporter.Export(sourceDB))
'once the export is complete close the stream
Call opstream.Close

  'mark the flow of control moving out of  the current function
exportDBDxl=True
Exit Function
'display the errors that resulted in abrupt termination
errHandler:
Print "Error ***" & Error & " occured on line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err)  & "*** while attempting to export dxl of specified database"
Msgbox "Error ***" & Error & " occured on line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err)  & "*** while attempting to export dxl of specified database"
Exit Function
End Function


Hope this helps:)

Lotusscript code to add attachment to a richtext field

The following is a lotus script code that will help you add an attachment to a rich text field

Function addAttachmentToRichTextField(doc As NotesDocument,rtField As String,filePath As String) _
As Boolean
'***********************************************************
'@Purpose : add a file denoted by the filepath to a richtext field
'@Author   : Karthikeyan A
 '@Param : doc As NotesDocument - the document which contains the rich text field
'@Param : rtField As String - the name of the rich text field in which the attachment is to added to
'@Param : filePath As String - the path of the file that needs to be attached
   '@Note : The doc specified here must not be a new one. 
' That is doc.IsNewNote must be 0
'*********************************************************** 

'mark the flow of control moving into  the current function
addAttachmentToRichTextField=False

'declare variables and objects necessary for further manipulation
Dim rtItem As NotesRichTextItem

'handle errors in case of abrupt termination
On Error Goto errHandler

'set the handle of the richtext item associated with the rtfield name
Set rtItem=doc.GetFirstItem(rtField)
'embedd the file as an attachment to the richtext field
Call rtitem.EmbedObject ( EMBED_ATTACHMENT, "", filePath)
'save the document
Call doc.Save( True, False )

'mark the flow of control moving into  the current function
addAttachmentToRichTextField=True

Exit Function
'inform the user regarding the error that results in abrupt termination
errHandler:
Print "Error ***" & Error & "*** occured on line ***" & Cstr(Erl) & "*** with error number ***"   _
& Cstr(Err) & "*** in Method ""addAttachmentToRichTextField"" "
Msgbox "Error ***" & Error & "*** occured on line ***" & Cstr(Erl) & "*** with error number ***"   _
& Cstr(Err) & "*** in Method ""addAttachmentToRichTextField"" "
Exit Function
End Function


Hope this helps :)

Wednesday, November 24, 2010

Send HTML Content As Mail using Lotus Script

The following function will help you send html content as a mail


****************************************************************************
Function sendHTMLContentAsMail(recipients As Variant,ccTo As Variant,bccTo As Variant, _
Subject As String,bodyHtmlContent As String)
'Declare Variables 
Dim s As New NotesSession
Dim db As NotesDatabase
Dim body As NotesMIMEEntity
Dim stream As NotesStream
Dim host As String
Dim message As  NotesDocument 

On Error Goto errHandler

Set db = s.CurrentDatabase
Set message=db.CreateDocument
'Capture the server name and filepath for use in URLs
Dim ServerName As New NotesName( db.Server )
host = "http://" + ServerName.Common & ".com"

s.ConvertMIME = False ' Do not convert MIME to rich text
Set stream = s.CreateStream
Set body = message.CreateMIMEEntity
message.Subject =Subject
message.SendTo =recipients
message.CopyTo =ccTo
message.BlindCopyTo =bccTo
message.RecNoOutOfOffice = "1"   
Call stream.WriteText (bodyHtmlContent)
' Ensure the MIME content will be recognized as HTML   (Must be after the stream is written)
Call body.SetContentFromText (stream, "text/html;charset=iso-8859-1", ENC_NONE) 
Call message.Send (False)  

s.ConvertMIME = True ' Restore conversion
Exit Function
errHandler:
Msgbox Error,,Cstr(Erl)
Exit Function
End Function
********************************************************************************


Hope this helps :)

Tuesday, November 23, 2010

Lotusscript code to append hotspot to a richtext field

My aim is to append a Link hotspot to the rich text field of a notes document as illustrated in the following image on a button click



The following code helped me perform the same
/***************************************************************************/
Function AppendHotspotLink (rtitem As NotesRichTextItem, url As String) As String
'** This function will attempt to append a button to a given
'** NotesRichTextItem, using code that has been assigned
'** to this object after it has been created (using the SetCode
'** method). The code language (as set with the SetLanguageType
'** method) can be either LotusScript or Formula language.

'** If there is an error creating the button (often because the code
'** doesn't compile correctly), this function will return the error
'** message. If the button is created properly, an empty string
'** will be returned.
On Error Goto processError

'** if no rich text item was given to us, just exit without doing anything
If (rtitem Is Nothing) Then
Exit Function
End If

Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim body As NotesRichTextItem
Dim importer As NotesDXLImporter

Dim buttonCode As String
Dim buttonTag As String
Dim dxl As String

'** set up the DXL to be used for the code in the button
%REM
If (buttonLanguage = RTB_LOTUSSCRIPT) Then
buttonCode = |<lotusscript>Sub Click(Source As Button)
| & XmlConvert(code) & |
End Sub</lotusscript>|
Else
buttonCode = |<formula>| & XmlConvert(code) & |</formula>|
End If



buttonTag = |<button width='2in' widthtype='fitcontent' wraptext='true' |
If (edgeType = RTB_SQUARE) Then
buttonTag = buttonTag & | edge='square' |
Else
buttonTag = buttonTag & | edge='rounded' |
End If
buttonTag = buttonTag & | bgcolor='system'>|
%END REM

'** DXL that will create a temporary doc with the button we want.
'** We're adding the current user name in an Author field on
'** this temporary document because we'll be deleting it at the end
'** of this function, and the user may only have Author access to
'** this database.
dxl = |<?xml version='1.0' encoding='ISO-8859-1'?>
<!DOCTYPE document SYSTEM 'xmlschemas/domino_8_5.dtd'>
<document xmlns='http://www.lotus.com/dxl' version='8.5.1'
 replicaid='0123456789ABCDEF' form='ButtonMaker'>
<item name='DocAuthor' authors='true' names='true'>
<text>| & XmlConvert(session.CommonUserName) & |</text></item>
<item name='Body'><richtext>
<pardef id="1" />
 <par def="1">
 <actionhotspot>
<code event="click">
  <formula>@URLOpen("|& url &|")</formula>
  </code>
  Document Link
  </actionhotspot>
  </par>
</richtext>
</item>
</document>|


'** create a new doc using the DXL above
Set db = session.CurrentDatabase
Set importer = session.CreateDXLImporter(dxl, db)
importer.ReplicaRequiredForReplaceOrUpdate = False
importer.DocumentImportOption = DXLIMPORTOPTION_CREATE
Call importer.Process

'** get the button from the doc we just created and append it to
'** the rich text item we were given
Set doc = db.GetDocumentByID(importer.GetFirstImportedNoteId)
Set body = doc.GetFirstItem("Body")
Call rtitem.AppendRTItem(body)

'** try to delete the temporary doc. In case we can't delete it for some
'** reason, a scheduled agent should be written to globally delete
'** docs that use the form name specified in the DXL above.
On Error Resume Next
Call doc.RemovePermanently(True)

Exit Function


processError:
If (importer.Log <> "") Then
AppendHotspotLink = importer.Log
Else
AppendHotspotLink = "Error " & Err & " on line " & Erl & ": " & Error$
End If
Exit Function
End Function




Function XmlConvert (txt As String) As String
'** get rid of the text characters that XML doesn't like (accented
'** characters are usually okay, as long as you use an encoding
'** like ISO-8859-1
XmlConvert = txt
XmlConvert = Replace(XmlConvert, "&", "&amp;")
XmlConvert = Replace(XmlConvert, "<", "&lt;")
XmlConvert = Replace(XmlConvert, ">", "&gt;")
End Function

Note: Use the following code to test the above function

%rem


Dim session As New NotesSession
Dim doc As NotesDocument
Dim rtitem As NotesRichTextItem

Dim result As String

'** grab the first selected doc in the view
Set doc = session.CurrentDatabase.UnprocessedDocuments.GetFirstDocument
Set rtitem = doc.GetFirstItem("Body")
If (rtitem Is Nothing) Then
Set rtitem = New NotesRichTextItem(doc, "Body")
End If

Call AppendHotspotLink(rtitem,"http://www.google.com")

'** save and exit
Call doc.Save(True, True)


%end rem

Wednesday, November 10, 2010

get Current Folder Path in Java

The following function helps you get the current folder path of your project


@SuppressWarnings("finally")
public String getCurrentFolderPath() {
String path = "";
try {
path = new java.io.File(".").getCanonicalPath();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
return path;
}
}

Hope this helps :)

CopyDirectory Function in Java

The following function will help you copy a directory from one location to an other.I got this good function with the help of my friend google :)


public void copyDirectory(File sourceLocation , File targetLocation)
   throws IOException {
       
       if (sourceLocation.isDirectory()) {
           if (!targetLocation.exists()) {
               targetLocation.mkdir();
           }
           
           String[] children = sourceLocation.list();
           for (int i=0; i<children.length; i++) {
               copyDirectory(new File(sourceLocation, children[i]),
                       new File(targetLocation, children[i]));
           }
       } else {
           
           InputStream in = new FileInputStream(sourceLocation);
           OutputStream out = new FileOutputStream(targetLocation);
           
           // Copy the bits from instream to outstream
           byte[] buf = new byte[1024];
           int len;
           while ((len = in.read(buf)) > 0) {
               out.write(buf, 0, len);
           }
           in.close();
           out.close();
       }
   }

Usage:

                File source=new File("c:\\ak");
File target=new File("c:\\bk");
try {
copyDirectory(source,target);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Hope this helps :)

Tuesday, November 9, 2010

Setting up Offline Password in Domino Quickr

In order for a user to go offline in Quickr-D, his/her offline password needs to be configured.

If in case a user proceeds further with out configuring a offline password he/she might experience the following error message when attempting to create a offline station in quickr-D
error requesting offline configuration from the server

To configure the offline password follow the following steps,
  • 1.       Open up the place which the user wants to go offline with
  • 2.       Go to the member’s section and open up the member profile


  •    Edit the Member profile by clicking the Edit button
  •    Scroll down and configure the offline password for the user and click next




Tuesday, November 2, 2010

Open Xpage from a Notes Form or View on Notes Client 8.5.1

In order to open a xpage ( say a document on a xpage) from a Notes Form or View from the notes client, use a button or a hot spot that contains a code fragment similar to the following,

@URLOpen("notes://servername/databasepath/XpageName.xsp?openXPage&documentId=documentUniqueID&action=editDocument")

Note the usage of the word openXPage in the query string. Ensure that it is present there, 'cos the XPage wont open up if it does not have this part in the url and instead it will open up the default view of the database instead.


Hope this Helps  :)


Monday, November 1, 2010

Setting "Do not locally Encrrypt" by default

Copying Databases into our local file system with encryption is one of the head ache in most of the times when u really dont want any security to be associated with the database being copies, example POCs etc

Setting this property is some thing that I use time and again and forget where I did it.

Hope the following piece of info helps people recollect this stuff.

-->choose File
-->Security
-->User Security 
--> Notes Data 
--> Notes Databases 
--> select "Do not locally encrypt" 
--> click OK

It is as illustrated in the following image,



:)

Friday, October 22, 2010

Single Copy XPages Design - SCXD - Lotus Notes 8.5.2

I recently stumbled upon a brand new feature of Lotus Notes 8.5.2.

It is about Single Copy XPages Design. Following URL Has exhaustive description about the same and it seems quite interesting too...

http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Single_Copy_XPage_Design

Hope this helps :)

Thursday, October 21, 2010

Opening Documents from Views in a different tab on the same XPage

I happened to perform an R&D on how to open up documents on new tabs with in the same XPage when you click on links in XPage views.

I searched for ideas over the net and I got the idea of using Dojo tabs as Dojo is shipped with XPages.

After an exhaustive search for the resources on web I arrived at the desired results.

Following is an abstract of how I got the same to work on XPages.

Create a Form, map it to a View and  create a few documents.
Now Create an XPage and bind the same to your form and map all the test fields that you have on your form to the xpage
Now Create an other XPage and put the following code into it

  Step 1: Enclose the following style imports to an XPage
        @import "../resources/dojo.css"; 
        @import "../dijit/themes/tundra/tundra.css";

  Step 2: Include the dojo.xd.js into the XPage using the following script tag
    <script type="text/javascript" src="dojo.xd.js"
        djConfig="parseOnLoad: true">
    </script>
   
  Step 3: Add the following scripts to the XPage
        dojo.require("dojo.parser");
        dojo.require("dijit.layout.ContentPane");
        dojo.require("dijit.layout.TabContainer");
        dojo.require("dijit.form.Button"); dojo.require("dojo.widget");       


Step 4: Put the following html on the page
    <h1>Tab Container </h1>
    <div id="mainTabContainer" dojoType="dijit.layout.TabContainer"
        style="width:500px;height:500px">
        <div id="tab1" dojoType="dijit.layout.ContentPane"
            title="Open Docs in New Tab" selected="true">
        </div>
        <div id="tab2" dojoType="dijit.layout.ContentPane"
            title="Normal Way">
        </div>
    </div>

Now DRAG AND DROP your View into the DIV WITH ID "tab1".



Now switch to the data tab of the same column and key in the following code, as shown in the following figure,

-----------------------------------
"<a href='#' onclick='addTab(\""+rowData.getColumnValue("Name")+"\",\""+
rowData.getUniversalID()+"\")'>"+rowData.getColumnValue("Name")+"</a>"

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

Now create a Server script library by the name, commonFunctions and include the same on to your XPage.
Put the following function into that script library and save the same.

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

function addTab(tabTitle,unid){

    var url="http://andromeda/dojo/XPageDojoTabsTest.nsf/openform.xsp?documentId="+    unid +"&action=editDocument";
    var tabs = dijit.byId("mainTabContainer");
   
    var pane = new dijit.layout.ContentPane({
        title:tabTitle,
        content:"<iframe border='0px solid #ffffff' frameborder='0' src='"+url+"'> </iframe>",
        closable:true
    });
   
    tabs.addChild(pane);
    tabs.selectChild(pane);
}

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

Once this is complete you are good to go... Preview your XPage on the Browser or the Notes Client and click on the links that appear in the view.
When you click on the links you can visuallize the documents getting opened on new tabs,
There you go, a POC...

Hope this helps :)

Tuesday, October 19, 2010

Binding Richtext Fields and File Upload Controls in XPages

The following is a simple POC that describes how file upload controls on XPages work when bound to Rich text fields in Notes Forms.

Create a Simple form with 2 Rich Text fields and bind them to two file upload controls respectively on a Xpage as shown in the following figure and save them.


Now Preview the XPage, add a couple of attachments and Save the XPage


The code that I used in the upload button here is - currXPDoc.save() where currXPDoc is my datasource's name

Thus a document gets saved in the back end. Opening the same will help you find the attachments embedded into their respective richtext fields as follows,

Hope this helps :)



Wednesday, October 6, 2010

Running Scheduled Agents from Server Console

When working with scheduled agents, we often tend to run the agent by right clicking it and clicking on run or calling it on a button click before we schedule it. It may not work always, cos scheduled agents will have a lot of issues that are not associated with a normal agent which may run properly with your security permissions when you run it.

For example you may have a role enabled for you on the ACL where as your server may not.
So Scheduled when they run automatically will run with server rights over the database and hence may result in different results.

So the best way I know to test the working of a scheduled agent is by running it through the following command,

Tell Amgr Run "DatabasePath" 'AgentName'

Mind the usage of the single and the double quotes. They must not be changed.

Hope this helps :)

Monday, October 4, 2010

Expanding and Collapsing Categories in a XPage View

For expanding and Collapsing category entries in an XPage,
   Go the all properties section of the XPage, Navigate to Data -> Data -> Expand Level as illustrated in the following figure

Specifying 0 here will collapse all entries and 1 will expand the same.

Also in case of a view containing multiple category columns, 1 will expand the first level categories with the other levels like 2nd or 3rd or so on collapsed.

Like wise specifying 2 here will expand the first category as well as the second category where as the 3rd or 4th or so on will be collapsed

Using a session scoped variable or a request scoped variable we can probably compute this on button clicks which might be handy for the end users...

Hope this helps :)



Tuesday, September 28, 2010

OnUnload event in XPages

Add the following script block to your xpage. Preview the same and  close it. Once you close your XPage you will get a prompt which depicts the triggering of the onUnload event in xpages.

 <xp:scriptBlock>
<xp:this.value escape="false">
window.onunload=function() {
alert('I run on window unload');
}
</xp:this.value>
</xp:scriptBlock> 

A little bit of client techniques to include server side scripts will also work here.

Hope this helps:)


Monday, September 20, 2010

Getting User's Name on the XPage

The content that I am trying to describe on this particular post is fairly simple. Many of you guys out there would have faced it and solved it. But still I would like to share this cos, really XPages are stupid at times.

I had the formula session.getCommonUserName() on a lable which worked for me through out the period I was developing my last application. When I moved the same to a test server to test the same, to my astonishment I found that the label with the above mentioned code displaying my test server's name.

I opened up the XPage in designer, saved it manually,
Signed the database using server id,
compacted the database ,
Restarted my test server etc etc...

All of the above steps failed and it still kept displaying my server name

Later I changed the code to @Name("[CN]",@UserName()), the formula eqivalent in server script.
OOPS that failed tooo...

And after a few brief moments of frustrations, I got the following idea,
@Name("[CN]",session.getEffectiveUserName())

And that eventually saved me.

Feels strange aaha...

Hope this helps :)

Roles in XPages

I had a hard time working with user roles in XPages.

  I used to the following procedure which is a server script equivalent of the lotus script equivalent of the @UserRoles which wont work on server side javascript :) (confusing aaha...)

var acl:NotesACL= database.getACL();
var entry:NotesACLEntry = acl.getEntry(@Name("[CN]",@UserName()))
if (entry==null)    {
    entry = acl.getEntry(session.getUserName())
}
 
if (entry==null)    {
    return "";
}

entry.getRoles();


It did work to some extent. But I really had a very tough time with this. It seemed to work fine for a while but to my astonishment it started showing only my server's role enabled on the database . It was very irritating and I felt ridiculous about it.

Later I explored the web to arrive at the fairly simple decent solution as follows,

context.getUser().getRoles();

Yes the above mentioned line did the job for me. Hope this helps some one :)

Tuesday, September 14, 2010

Recover a corrupted archive of the Excel format

One of the readers suggested the following tool for recovering corrupted excel files.

It feels like a handy tool to help in case of excel file corruptions. Also it covers a wide variety of files like *.xls, *,xlt, *.xlsx, xlsm, *.xltm, *.xltx, *.xlam.

I haven't had a chance yet to use it 'cos i dont have a corrupted excel file for the time being (but yes of course have gone through its features :)


Wish I could have had it few months back :).

For more details about the recovery tool click here
 Not feeling patient.... K download it directly



Hope this Helps :)


Sunday, August 15, 2010

Embedding Video in a Web Page

The following is a sample code that shall help you embed a custom vedio of your choice in a web page.

Note: This code works fine in IE/Fire Fox. Holds good when included in a XPage as well. The same fails when previewed on notes client though... i mean XPages in 8.5.1

The code below shall have two fragments one is <object> tag for IE and  <Embed> for Firefox,

Hence you got to specify your video url in two places in the following code.


<object ID="MediaPlayer" WIDTH="400" HEIGHT="300" CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" STANDBY="Loading Windows Media Player components..."
TYPE="application/x-oleobject">   <param NAME="FileName" VALUE="http://www.youtube.com/v/bz6BA1heMSI?fs=1&amp;hl=en_US" />
<param name="ShowControls" VALUE="true" />
<param name="ShowStatusBar" value="false" />
<param name="ShowDisplay" VALUE="false" />
<param name="autostart" VALUE="true" />
<embed TYPE="application/x-mplayer2" SRC="http://www.youtube.com/v/bz6BA1heMSI?fs=1&amp;hl=en_US" NAME="MediaPlayer" WIDTH="400" HEIGHT="300" ShowControls="1" ShowStatusBar="0" ShowDisplay="0" autostart="1">   </EMBED> </OBJECT>

Thursday, August 5, 2010

Delete Documents from a View - A Simple Generic Function in Lotusscript


Function deleteSelectedDocuments As Boolean
'***********************************************************
'@Purpose : To delete all the selected documents from a view
'@Author   : Karthikeyan A
'***********************************************************
'mark the flow of control getting inside the current function
deleteSelectedDocumentsv=False
     'declare all variables and objects necessary for further manipulation
Dim session As New NotesSession
Dim workspace As New NotesUIWorkspace
Dim database As NotesDatabase
Dim documentCollection As NotesDocumentCollection
Dim userChoice As Integer
'handle errors in case of abrupt termination
On Error Goto errHandler
'set the handle for the current database
Set database=session.CurrentDatabase
'set the handle for the selected documents
Set documentCollection=database.UnprocessedDocuments
'if no documents are selected then inform the same to the user and exit
If documentCollection.Count=0 Then
Msgbox "You have not selected any documents. Please choose some to delete em",,"No documents selected"
Else 
'if user has selected a few documents then ask his confirmation before deleting the same
userChoice=Msgbox ("Do you want to delete " & Cstr(documentCollection.Count) & " document(s)?",64+100, _
"Please confirm...")
'if the user confirms then delete the documents
If userChoice=6 Then
Call documentCollection.RemoveAll(True)
Call workspace.ViewRefresh
End If
End If
'mark the flow of control moving out of  the current function
deleteSelectedDocumentsv=True
Exit Function
errHandler:
Print "Error ***" & Error & " occured on line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err)  & "*** while attempting to delete selected documents"
Msgbox "Error ***" & Error & " occured on line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err)  & "*** while attempting to delete selected documents"
Exit Function
End Function