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 :)