Events not firing in ToolPart

2. May 2007 10:35 by Mrojas in General  //  Tags:   //   Comments (0)
I was developing a WebPart and I came up with a situation where my custom ToolPart did not fired the events. I found this post that solved the problem. " I moved the databinding code into the CreateChildControls() code: protected override void CreateChildControls() { dllCatagory = new DropDownList(); dllCatagory.Visible = true; dllCatagory.AutoPostBack = true; dllCatagory.Attributes.Add("runat", "server"); dllCatagory.SelectedIndexChanged += new EventHandler(dllCatagory_SelectedIndexChanged); CdCatagoryList.CatagoryList cdCatL; cdCatL = new CdCatagoryList.CatagoryList(); //cdCat.Catlist is a dll that will get the data. DataView tviewFolders = cdCatL.CatList(true, "cdadmin", "", "server=;uid=DataSa;pwd=pa456;database=ContentDepot"); dllCatagory.DataSource = tviewFolders; dllCatagory.DataValueField = "FolderNumber"; dllCatagory.DataTextField = "FolderName"; dllCatagory.DataBind(); Controls.Add(dllCatagory); } public void dllCatagory_SelectedIndexChanged(object sender, EventArgs e) { //Code to load the gridview //This event now fires} protected override void RenderToolPart(HtmlTextWriter output) { EnsureChildControls(); dllCatagory.RenderControl(output); } "

Extracting images from a word document

30. April 2007 10:48 by Mrojas in General  //  Tags: ,   //   Comments (0)
I recently had a situacion where I needed to extract images from a word document. This can be cumbersome, tedious and you can loose the fidelity of your images I found two good aproaches: first see Approach One. This approach indicates to save the document as a web page. In my case I needed images with a sequence I could follow. Like Figure1 Figure2 etc and I needed them with the best quality possible. So I used another link recommended Approach Two which has a macro that you can use to export your image as bmp. Those two links were of great help to me. I recommended them.

Get IP Address for Db2 clients

26. April 2007 09:14 by Mrojas in General  //  Tags: ,   //   Comments (0)

Source IP for connected applications in DB2

Usually when there are performance problems you need to track who is connected to the database. Especially in development environments because production environments are more restricted with who has access to the DB.

You can easily list the applications connected to your DB2 database using the control center application or from the command line.

From the control center:

  1. First check that the Objects Detail Pane is active

  1. In the Objects Details Pane, click the application list link

  1. This will open a window like this:

From the command window just do something like:


Now to get the real juicy and useful information execute from the command line:


And use the number that is under the Appl. Handle column, this will show the ip address and other info.


22. February 2007 18:04 by Mrojas in General  //  Tags:   //   Comments (0)
I like Linux and consider it as a very interesting OS alternative
However sometimes there are simple things that I just do not know how to do.
Windows is still everywhere and specially getting thing
from a Windows to a LINUX box can be tricky.
For example recently I had to restore a database
from a Windows DB2 to a Linux DB2 so I had the backup and needed to
eove it to the linux box.
So use smbclient!
But how.
to connect to a windows share do something like this:

smbclient -user domain/username //machine/sharename

this thing will ask for your password and now you are connected.
Smbclient is just like an ftp.
But how do you copy a directory
I found these instructions in the internet:

smb: > tarmode
smb: > lcd /tmp
smb: > recurse
smb: > prompt
smb: > mget your_directory/

as simple as that.
So hope that helps

Printing in Java

2. February 2007 11:20 by Mrojas in General  //  Tags:   //   Comments (0)

Sample Code to Print in Java

import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;

public class Class3 {

static String textToPrint = "Richard North Patterson's masterful portrayals of law and politics at the apex of power have made him one of our most important\n" +
"writers of popular fiction. Combining a compelling narrative, exhaustive research, and a sophisticated grasp of contemporary\n" +
"society, his bestselling novels bring explosive social problems to vivid life through characters who are richly imagined and\n" +
"intensely real. Now in Balance of Power Patterson confronts one of America's most inflammatory issues-the terrible toll of gun\n" +
"violence.\n\n" +
"President Kerry Kilcannon and his fiancée, television journalist Lara Costello, have at last decided to marry. But their wedding\n" +
"is followed by a massacre of innocents in a lethal burst of gunfire, challenging their marriage and his presidency in ways so shattering\n" +
"and indelibly personal that Kilcannon vows to eradicate gun violence and crush the most powerful lobby in Washington-the Sons of\n" +
"the Second Amendment (SSA).\n\n" +
"Allied with the President's most determined rival, the resourceful and relentless Senate Majority Leader Frank Fasano, the SSA\n" +
"declares all-out war on Kerry Kilcannon, deploying its arsenal of money, intimidation, and secret dealings to eviscerate Kilcannon's\n" +

"crusade and, it hopes, destroy his presidency. This ignites a high-stakes game of politics and legal maneuvering in the Senate,\n" +

"the courtroom, and across the country, which the charismatic but untested young President is determined to win at any cost. But in\n" +

"the incendiary clash over gun violence and gun rights, the cost to both Kilcannons may be even higher than he imagined.\n\n" +

"And others in the crossfire may also pay the price: the idealistic lawyer who has taken on the gun industry; the embattled CEO\n" +

"of America's leading gun maker; the war-hero senator caught between conflicting ambitions; the female senator whose career is at\n" +

"risk; and the grief-stricken young woman fighting to emerge from the shadow of her sister, the First Lady.\n\n" +

"The insidious ways money corrodes democracy and corrupts elected officials . . . the visceral debate between gun-rights and\n" +

"gun-control advocates . . . the bitter legal conflict between gun companies and the victims of gun violence . . . a\n" +

"ratings-driven media that both manipulates and is manipulated - Richard North Patterson weaves these engrossing themes into an\n" +

"epic novel that moves us with its force, passion, and authority.";

public static void main(String[] args) {

DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;

PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();

/* locate a print service that can handle it */

PrintService[] pservices = PrintServiceLookup.lookupPrintServices(flavor, aset);

/* create a print job for the chosen service */

int printnbr = 1;

DocPrintJob pj = pservices[printnbr].createPrintJob();

try {

/* * Create a Doc object to hold the print data.

* Since the data is postscript located in a disk file,

* an input stream needs to be obtained

* BasicDoc is a useful implementation that will if requested

* close the stream when printing is completed.


ByteArrayInputStream fis = new ByteArrayInputStream(textToPrint.getBytes());

Doc doc = new SimpleDoc(fis, flavor, null);

/* print the doc as specified */

pj.print(doc, aset);


catch (Exception ex){





TIP: If you are just testing create a Printer. Just go to Add Printers, select FILE for port and Manufacturer Generic and TEXT Only

57016 or the Unavailable table

17. January 2007 06:57 by Mrojas in General  //  Tags: ,   //   Comments (0)
The idea was to create a harry potter like title jeje.
Today I had a new issue with DB2 (everyday you learn something new).
I got to work and we had some tables that you could not query or do anything. The system reported something like:
SQL0668N  Operation not allowed for reason code "1" on table "MYSCHEMA.MYTABLE".
So I started looking what is an 57016 code????

After some googling I found that the table was in an "unavailable state". OK!!
But how did it got there? Well that I still I'm not certain. And the most important. How do I get it out of that state?????
Well I found that the magic spell is somehting like
>db2 set integrity for myschema.mytable immediate checked

After that statement everything works like a charm.
DB2 Docs state that:
"Consider the statement:

Situations in which the system will require a full refresh, or will check the whole table
for integrity (the INCREMENTAL option cannot be specified) are:
  • When new constraints have been added to T itself
  • When a LOAD REPLACE operation against T, it parents, or its underlying tables has taken place
  • When the NOT LOGGED INITIALLY WITH EMPTY TABLE option has been activated after the last integrity check on T, its parents, or its underlying tables
  • The cascading effect of full processing, when any parent of T (or underlying table, if T is a materialized query table or a staging table) has been checked for integrity non-incrementally
  • If the table was in check pending state before migration, full processing is required the first time the table is checked for integrity after migration
  • If the table space containing the table or its parent (or underlying table of a materialized query table or a staging table) has been rolled forward to a point in time, and the table and its parent (or underlying table if the table is a materialized query table or a staging table) reside in different table spaces
  • When T is a materialized query table, and a LOAD REPLACE or LOAD INSERT operation directly into T has taken place after the last refresh"
But I really dont know what happened with my table.
Hope this help you out.

Java and Active Directory

10. January 2007 11:25 by Mrojas in General  //  Tags:   //   Comments (0)
   Active Directory is also LDAP. So to integrate with the Active Directory you can use code very similar to that one used with other LDAP servers.

To connect to the Active Directory you can do something like this:

import java.util.Hashtable;
import javax.naming.NamingException;

  * @author mrojas

public class Test1

      public static void main(String[] args)

            Hashtable environment = new Hashtable();
            //Just change your user here       
String myUser = "myUser";
            //Just change your user password here      

            String myPassword = "myUser"; 

            //Just change your domain name here

            String myDomain = "myDomain";

            //Host name or IP

            String myActiveDirectoryServer = "";

            environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
            environment.put(Context.PROVIDER_URL, "ldap://" + myActiveDirectoryServer + ":389");
            environment.put(Context.SECURITY_AUTHENTICATION, "simple");
            environment.put(Context.SECURITY_PRINCIPAL, "CN=" + myUser + ",CN=Users,DC=" + myDomain + ",DC=COM");
            environment.put(Context.SECURITY_CREDENTIALS, myPassword);
                  DirContext context = new InitialDirContext(environment);
System.out.println("Lluvia de exitos!!");
            catch (NamingException e)

Creating Excel files from Coldfusion

4. January 2007 05:55 by Mrojas in General  //  Tags:   //   Comments (0)
I  found a super interesting blog called Busy ColdFusion Developers' Guide to HSSF Features

HSSF is part of an open source java project that provides FREE OPEN SOURCE libraries to create Microsoft Office Files like Microsoft Word or Microsoft Excel.

So I was wondering could it be possible with Coldfusion to use those libraries. Specially now that Coldfusion MX relies heavily in Java. So I found this wonderfull blog that explains it all.


It just went to the HSSF download site:


The project that holds these libraries is called POI.

When you enter in those links there is a release directory and a bin directory. I downloaded the zip file and you will find three files like: poi-Version-Date.jar; poi-contrib-Version-Date.jar and poi-scratchpad-Version-Date.jar


I downloaded the 2.5.1-final version. I renamed my jars to poi-2.5.1.jar, poi-2.5.1-contrib.jar and poi-2.5.1-scratchpad.jar because my memory cannot hold those complex names for a long time. I installed the library in C:\POI and put them in the Coldfusion Administrator classpath




And then I created a test file like the following:


Note: I used a recommendation from Cristial Cantrell


    context = getPageContext();
    response = context.getResponse().getResponse();
 response.setHeader("Content-Disposition","attachment; filename=unknown.xls");

    out = response.getOutputStream();

<cfset wb = createObject("java","org.apache.poi.hssf.usermodel.HSSFWorkbook").init()/>
<cfset format = wb.createDataFormat()/>
<cfset sheet = wb.createSheet("new sheet")/>
<cfset cellStyle = wb.createCellStyle()/>
<!--- Take formats from: --->
<cfset cellStyle.setDataFormat(createObject("java","org.apache.poi.hssf.usermodel.HSSFDataFormat").getBuiltinFormat("0.00"))/>

<cfloop index = "LoopCount" from = "0" to = "100">
<!---  Create a row and put some cells in it. Rows are 0 based. --->
<cfset row = sheet.createRow(javacast("int",LoopCount))/>

<!---  Create a cell and put a value in it --->
<cfset cell = row.createCell(0)/>
<cfset cell.setCellType( 0)/>
<cfset cell.setCellValue(javacast("int",1))/>

<!--- Or do it on one line. --->
<cfset cell2 = row.createCell(1)/>
<cfset cell2.setCellStyle(cellStyle)/>
<cfset cell2.setCellValue(javacast("double","1.223452345342"))/>
<cfset row.createCell(2).setCellValue("This is a string")/>
<cfset row.createCell(3).setCellValue(true)/>


<cfset wb.write(out)/>
<cfset wb.write(fileOut)/>
<cfset fileOut.close()/>
<cfset out.flush()/>

PowerScript to VB.NET

31. December 2006 08:26 by Mrojas in General  //  Tags:   //   Comments (0)

If you are migrating a Powerbuilder Application to .NET the more recommend language you can use is VB.NET. This because this language has a lot of common elements with PowerScript. Lets see some simple comparisons.

Variable definition

A variable is defined writing the Data Type just before the name.

For example:

Integer amount

String name


In VB.NET this will be

Dim amount as Integer

Dim name as String




constant integer MAX = 100


In VB.NET this will be

Const MAX As Integer = 100


Control Flow: If Statement


      If monto_cuota=13 Then

                nombre= 'Ramiro'

      ElseIf monto_cuota=15 Then

             nombre= 'Roberto'


          nombre= 'Francisco'

      End If

This code is almost exactly the same in VB.NET


        If monto_cuota = 13 Then

            nombre = "Ramiro"

        ElseIf monto_cuota = 15 Then

            nombre = "Roberto"


            nombre = "Francisco"

        End If


Control Flow: Choose Statement


      Choose case monto_cuota

          Case Is< 13: nombre='Ramiro'

          Case 16 To 48:nombre= 'Roberto'



      End Choose

This code is slightly different:

  Dim monto_cuota As Integer

        Dim nombre As String

        Select Case monto_cuota

            Case Is < 13

                nombre = "Ramiro"

            Case 16 To 48

                nombre = "Roberto"

            Case Else

                nombre = "Francisco"

        End Select






Control Flow: For statement


      For n = 5 to 25 step 5


      a = a+10






Dim n, a As Integer

      For n = 5 To 25 Step 5

            a = a + 10




Control Flow: Do Until, Do While


integer A = 1, B = 1

//Make a beep until variable is greater than 15 variable

DO UNTIL A > 15 


    A = (A + 1) * B




integer A = 1, B = 1

//Makes a beep while variable is less that 15

DO WHILE A <= 15


A = (A + 1) * B





        Dim A As Integer = 1, B As Integer = 1

        'Make a beep until variable is greater than 15 variable

        Do Until a > 15


            a = (a + 1) * B


        'Makes a beep while variable is less that 15

        Do While A <= 15


            a = (a + 1) * B


ASP to ASP.NET: File exists

31. December 2006 07:30 by Mrojas in General  //  Tags:   //   Comments (0)

This is the migration of a snippet of ASP classic to ASP.Net


Checking that a File Exists ASP Classic

Dim strExists  
Dim strNotExists 
Dim objFileSystemObjectVar
strExists    = "exists.txt"
strNotExists = "error.txt"
Set objFileSystemObjectVar = Server.CreateObject("Scripting.FileSystemObject")
' The FileExists method expects a fully qualified path and
' use Server.MapPath 
&quot;<%= strExists %>&quot; exists:
<b><%=objFileSystemObjectVar.FileExists(Server.MapPath(strExists)) %></b>
&quot;<%= strNotExists %>&quot; exists:
<b><%= objFileSystemObjectVar.FileExists(Server.MapPath(strNotExists)) %></b>


Checking that a file exists ASP.NET


<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>
<script language="VB" runat="server">
        Dim strExists As String = "exists.txt"
        Dim strNotExists As String = "error.txt"
&quot;<%= strExists %>&quot; exists:
&quot;<%= strNotExists %>&quot; exists:
<b><%= File.Exists(Server.MapPath(strNotExists))%></b>