XPages - HOW centralize column javascript in a scriptlibrary

Hi,

I have a xpage with a view control. In that control I have (icon) columns that are calculated with javascript.

This is what I use

if(viewEntry){

var idx = viewEntry.getColumnValues().get(6);

if (idx == 0) return;

var path = "/icons/vwicn" + ("00"+idx).right(3) + ".gif"

return "<IMG SRC='" + path + "' ALT=''>";

}

But what I sould like is to specify

return getIconImage(6)

And have the function defined in a javascript library or an other central location in my NSF.

function getIconImage(nr)

{

if(viewEntry){

var idx = viewEntry.getColumnValues().get(nr);

if (idx == 0) return;

var path = "/icons/vwicn" + ("00"+idx).right(3) + ".gif"

return "<IMG SRC='" + path + "' ALT=''>";

}

}

How can this be done?

Subject: Just do iit…

  • Put your function in a JS script library and include it as a resource on the XPage with your view control. Works for me.

Hope this helps…

Subject: Easy fix

because this is serverside javascript have to create a new SSJ library and add it as a resource to the custom control / xpage you are working on .

Create a function called getIconImage with the following code:

function getIconImage (intStatus)

{

switch(intStatus)

{

	case 10:	

           return "/icon.gif"

	default:

	   return "/default.gif";

}

}

and in the icon path specify something like this:

var code = viewEntry.getColumnValues().get(6);

return getIconImage(code)

should do the trick. Or you could add an image controlinside the column using code which uses the above code.