Dojo made easier to build model popup window with blur parent.It can be easily achieved using dijit.Dialog.Dojo dialog box acts like a web form on a sticky note. By overlaying the view page underneath it, the dialog box can use room for more form
controls. First look into some cool examples which can be done using dijit.Dialog.
Let's see in simple steps,
- I assume before start you already have dojo set up in your machine.
- Create DIV tag at the end of your web form and specify dojoType as dijit.Dialog. Along with that add id and title tag to DIV.E.g,
- Next you need to design your HTML which you're going to display in dialog box. Let's say simple address popup box. E.g,
- Pleace your HTML inside DIV tag which you've created in first step. E.g,
- At the end call your dialog box on any event using show() method of dijit. E.g,
- Check the output ,
Yesterday I was working on Audit trail functionality for one of my web form. I was using Rich text field to log activities on the form. Code was quite simple so done in few minutes and started testing.Chunk of my code was ,
Call rtitem.appendStyle(RtStyle)
Call rtitem.AppendText(tmpname.common)
Call rtitem.AddNewLine(1)
When I've started doing testing found AddnewLine property doesn't work fine and giving strange results.
I've tried to debug but not able to find what is wrong with AddNewLine method which works perfectly in client application. Next, I've decided to use PassThruHTML property of NotesRichTextStyle class and insert HTML directly into Rich Text field. When I've started testing the new code found RT field is not parsing HTML correctly.
Even I've used the same code which is mentioned in Notes help but didn't work.
I thought there must be a problem in putting RT field in HTML table , so I took out and placed outside table and verified but no use. My next debugging was from dojo side , I thought there must be something which I might have missed in dojo. I've spend couple of hours to test if anything went wrong in dojo but ended up with the same problem. At the end started looking IBM articles and found it's known bug which is reported five years back. To work around this issue, add brackets, [ ], around your string.When applied this work around everything works well ,
http://www-01.ibm.com/support/docview.wss?uid=swg21097539
I've couple of concerns, First, Why this bug is still there with R8.x versions ? This must be fixed long time back or they don't like to enhance Rich text capabilities in Lotus Notes.Second, Why AddNewLine property doesn't work properly on web like Notes client.
Have you ever encountered initialization error in building dojo application? . Most frequent errors are ; dojo is not loaded,getElementByid("..")/dojo.byId("..") is null or not an object, dijit widget is not loaded etc etc. It's certain that there is something wrong in parsing HTML, but it's not as easy to rectify like traditional HTML web pages.
Scenario |
You are using dojo.byId("..") or document.getElementById("..") on OnLoad event of the form and ended up with "dojo.byId("..") not defined or not an object" error. This is very common use of OnLoad event in Domino web applications.
Something about dojo.addOnLoad() |
Dojo's addOnLoad() makes sure that the DOM tree has been built by the browser and any other JavaScript that the handler references has been downloaded and evaluated.In dojo application we need to make sure that JavaScript resources that we’ve dojo.required and/or the DOM tree are ready for use.
What dojo.addOnLoad does ? |
dojo.addOnLoad takes a reference to a function and guarantees that the provided function is executed immediately after the following three conditions are met:
# The DOM tree has been built by the browser and is available for use by client code.
# All JavaScript resources demanded through the Dojo loader have been loaded.
# All Dojo widget parsing has been completed.Dojo lets you specify widgets directly in the HTML code. When you include Dojo widgets , Dojo must parse the HTML and replace each embedded widget with the actual HTML that implements the widget.
If djConfig.parseOnLoad is true, then this is accomplished as soon as the DOM tree is loaded by the browser but before any function registered with dojo.addOnLoad is executed.
Facts in using dojo.addOnLoad() |
# dojo.addOnLoad can be used any number of times.
# Each function given as an argument in dojo.addOnLoad() will be executed in the order it was provided.
Solution |
# Scenario 1 : Setting up value in variable(s) or pop-up alert to the user on onLoad event of the form.
Instead of ,
use like,
# Scenario 2 : Calling JavaScript function on onLoad event of the form ,
Instead of ,
use like,
# Scenario 3 : Attaching JavaScript function to any object on any event
( Note:JavaScript code is not allowed in the blog, write me for actual code )
When we need global declaration of variables or constants in more than one agent we usually create script library with those global declarations and link with the agent in order to use them.What about if same you wish to accomplish in Java ? Here are the simple steps,
# Create new Java library and add new class ,
public class GlobalDeclarations{ public static String viewName="ViewName1"; public static String viewName1="ViewName2"; . . . } |
# Save and close your Java library and include this library to the agent where these variables you intended to use.Including Java library in Java agent is explained here.
# In your Java agent use global variables like,
try{ Session session = getSession(); AgentContext agentContext = session.getAgentContext(); Database db = agentContext.getCurrentDatabase(); View vwConfig=db.getView(GlobalDeclarations.viewName); . . }catch(Exception e){ e.printStackTrace(); System.out.println(e.getMessage()); } |
In above example ,I've accessed global variable using classname.variablename . Using this technique all the global variables can be declared in separate Java library to avoid hard coding in complex agents.
Today I'm writing all small or big notes which must be considered in Domino Java development.I was collecting all these from past couple of weeks while doing my project.Hope it helps to others.
Removing unused class from Java Agent |
When you remove any existing class from a Java agent , it doesn't delete from agent class list until you remove from class file.
1- Click "Edit Project".
2- Select class from current agent files and click delete.
Incorporating a Java library with Java agent |
1- Click Edit Project from Java agent programmer's pane.
2- Select Shared Java Libraries.
3- Click "Add/Replace" button to add in agent files list.
Viewing output from a Java agent |
You can review output from a Java agent that is running locally in the Java Debug Console. To activate the console, choose File - Tools - Show Java Debug Console. To clear output from the window, click Clear.
If a Java agent is running on a server, the Java Debug Console output is redirected to a server log file. However sometimes you don't get log.nsf access on production servers.So it's better to incorporate log database with your working database. To log activity in Java code ,you can use my ActivityClass
Important Considerations |
1- Lotus Notes/Domino agents must extend AgentBase and use NotesMain() as the entry point for their functional code.However , In some cases you don't want to use NotesMain() class but you need to use domino classes.Such case you need to pass "Session" object as an argument.E.g; I've an activity logging class which doesn't use NotesMain() method to start.I Just pass "Sesssion" object to access domino methods/properties.
try { Session session = getSession(); AgentContext agentContext = session.getAgentContext(); Database db = agentContext.getCurrentDatabase(); ActivityClass activityLog= new ActivityClass(session); //Process table1 for form1 activityLog.addActivity(session,"Start pushing Form1 to Oracle."); PushOForm1 objForm1= new PushOForm1(session); qs= objForm1.tableUpdater(session); if(qs!="" || qs!=null){ activityLog.endActivity(session,qs); } //Process table2 for form2 activityLog.addActivity(session,"Start pushing Form2 to Oracle."); PushOForm2 objForm2= new PushOForm2(session); qs= objForm2.tableUpdater(session); if(qs!="" || qs!=null){ activityLog.endActivity(session,qs); } activityLog.closeActivity(session); }catch(Exception e) {e.printStackTrace();} |
2- Don't use "System.exit(0)" or "System.exit(1)" to exit, It throws SecurityException. In an application, System.exit may cause corruption problems.
3- Before deploying your Java project on server, make sure you've all permission set in java.policy file on server. You can find details in my previous article
4- To catch Lotus Notes Exception, use NotesException class .E.g,
try { Session session = getSession(); AgentContext agentContext = session.getAgentContext(); Database db = agentContext.getCurrentDatabase(); ActivityClass activityLog= new ActivityClass(session); . . . } // Catch if something wrong happens from Notes side like, Database/view failed to open or invalid formila etc catch(NotesException e) {System.out.println(e.id + " " + e.text);} // Usual Java Exception class catch(Exception e) { e.printStackTrace(); } |
5- Memory management is a consideration for long running programs and programs that create a large number of objects.If you get "Out of memory" error with your Domino-Java code use recycle method.The recycle method unconditionally destroys an object and returns its memory to the system.Java has no knowledge of the heavyweight back-end Domino Objects, only the lightweight Java objects representing them. Garbage collection has no effect on Domino Objects unless you first explicitly recycle them.
The Java Virtual Machine (JVM) starts out at 16MB of heap space and most of it is uncommitted. If the JVM needs more heap than it currently has, it will expand the heap in increments but will not exceed the maximum. Exceptions such as "java.lang.OutOfMemoryError" indicate that a heap has reached its maximum size. You can specify the number of bytes directly or use the suffix "MB" to indicate megabytes, for example, specifying "64MB" is the same as specifying "67108864."
Syntax: JavaMaxHeapSize=number of bytes
6- If you get "Can not find symbol" error in your code, It means something you've not declared and using.This error is similar to "Variable not declared" error in Lotus Script.But in Java this error is not descriptive and clear as Lotus Script.
7- Use NotesFactory class to access domino objects from third party IDE, like Eclipse.
8- At the end never forget to set Java agent security under Programmability Restrictions, fill in "Run unrestricted methods and operations" and "Run restricted LotusScript Java agents" as desired. These fields apply to all programmable interfaces and must be filled in for remote access.
Some weird experience |
1-We can see compilation errors on status bar while compiling Java agent.However sometimes I don't see any message, It doesn't matter how many times I click on "Compile All". Afterwards no change in Java code gets effect, I must need to re-start my Notes to fix this. Still it's happening :(
2-If by any chance my Notes gets crash, next time when I try to run my Java agent ; It throws "Class not found" exception . I need to edit and re-save my agent to make it work.
3-Sometimes when I do some changes in my agent, recompile and save the code and runs to see the output, I noticed it doesn't show results with updated code. It doesn't matter if I save with ctrl+s or using tool bar. I need to close my agent, then it asks me to save and I say yes to see the updated output.
I don't know if anyone else is facing this issues with 8.0(basic) IDE.
Some good IBM articles ,
# Using Lotus Notes with Eclipse to manage and run your Java programs
# Java access to the Domino Objects, Part 1
# Java access to the Domino Objects, Part 2
# Connecting Domino to the Enterprise Using
# Learning the Java Language
Continuation with my first Java project , Today I've started my second Java routine which will read Lotus Notes documents from other database and will push to Oracle.I've started with first class which handles one of the form ( still 16 forms to go :) ).Once code is written and tested , I've started reviewing my code which I always do to check if any logical or memory consumption stuffs are poorly coded.
While doing I got confused with public and static declaration . Initially I've done non static declaration of all JDBC objects;e.g,Connection, Statement and RecordSet on class level.Even I was reading "Java 2. The complete reference" book side by side but not able to find if I could get any performance benefit in for "static" declarations.So I've decided to test on execution time basis , don't know if it's the best way.Here is what I've done;
I've added "ExecutionTimer" class in my code,
public class ExecutionTimer { private long start; private long end; public ExecutionTimer() { reset(); } public void start() { start = System.currentTimeMillis(); } public void end() { end = System.currentTimeMillis(); } public long duration(){ return (end-start); } public void reset() { start = 0; end = 0; } } |
And I've used like
ExecutionTimer t = new ExecutionTimer(); t.start(); ProcessTable objProcesTable = new ProcessTable(session); objProcesTable.initiateObjects(session); t.end(); System.out.println("\n" + t.duration() + " ms"); |
Here in my class skeleton ,
public class ProcessTable { static private Connection conn; // or private Connection conn; static private Statement stmt; // or private Statement stmt; static private ResultSet rs; // or private ResultSet rs; public void initiateObjects(){ //Initiate all domino objects insert() //Insert record update() //Update record delete() //delete record } ProcessTable(){ // Prepare connectivity with Oracle } public void insert(){ //insert logic } public void update(){ //update logic } public void delete(){ //delete logic } } |
I've done some testing in my live environment with 10 records and found declaring these variables as static is faster than declaring public.I've tested thrice to make sure if network operation may create the difference. Here are results,
First test : ( In mills)
--------------------------------
Using non-static: 23791 ms
Using Static : 23134 ms
Second test:
--------------------------------
Using non-static : 23258 ms
Using Static : 21930 ms
Third test:
--------------------------------
Using non-static : 24556 ms
Using Static : 23227 ms
Here is what I've found in Java book ,
Instance variables declared as static are, essentially, global variables. When objects of its class are declared, no copy of a static variable is made. Instead, all instances of the class share the same static variable. Methods declared as static have several restrictions: ■ They can only call other static methods. ■ They must only access static data. ■ They cannot refer to this or super in any way. (The keyword super relates to inheritance and is described in the next chapter.) |
None of the above restrictions are applied in my case, so declaring static is faster approach ??? hope someone can enlighten on this.
I still remember those time when kids in India love to look and dance like Michael Jackson.He was enormously popular in those places where English speaking was rare.I never saw or heard such big fan following for any other Hollywood artist in India.He brought new era in Music and gave so much which nobody can give ever.
"Heal the world
Make it a better place
For you and for me and the entire human race
There are people dying
If you care enough for the living
Make a better place for
You and for me."
Whenever I listen this song, It gives so much emotions and feelings for those who are dying everywhere in the world.
It's great pain to see Media and few filthy people who has spoiled his name to gain popularity and killed the artist who deserved to live forever.I surprised to see still they are doing..
I pay my homage to the artist who gave soul to the music and feeling to love everyone in the world.
_________________________________________________________________________________May you rest in peace Michael !!!
_________________________________________________________________________________