Skip to main content link. Accesskey S

XPages Wiki

Submit Search

YouAtNotes XPages Wiki


Home > Formula > Useful formulas and code snippets
for details.

- Open the Eclipse package explorer (Windows -> open view)
- Edit to you database -> WebContent -> WEB-INF -> xsp.properties
- Add the following line:

xsp.html.doctype=<!DOCTYPE ...>


Set the DOCTYPE as you like.
editEdit

Useful formulas and code snippets

ShowTable of Contents
Here are some various snippets.

Get the current username


Use
session.getEffectiveUserName()
to the the name of the user who is logged on.
Use @Name() to convert it for exampel to a CN name:

@Name("[CN]", session.getEffectiveUserName())

Check if a user contains a certain role


context.getUser().getRoles().contains('[RoleName]');

Redirect to another XPage


context.redirectToPage("Page.xsp")


Reload a XPage every x seconds


in "beforePageLoad" event of the XPage:

var r = facesContext.getExternalContext().getResponse();
r.setHeader("Refresh", "1");


OR as meta tag: in "all properties" of the XPage -> resources -> add "metaData" with:

- content = 1
- httpEquiv = Refresh
- name = Refresh
- rendered = true


TimeDate handling

Set current datetime to a field in a document


var dt:NotesDateTime = session.createDateTime("Today");
dt.setNow();
doc.replaceItemValue("created", dt);

Get only the time of a datetime value


var nw = @Now();
return nw.toTimeString()

String handling

Replace all occurrences of one string by another


Use string.replace(searchstring, replacestring), this replaces all occurrences.
There seems to be a problem with the backslash \, this does not work:

s = s.replace("\\", "/")


The \ is only replaced once.
Workaround: use @ReplaceSubString(s, "\\", "/").

Formatting numbers


formatting with grouping and fixed fraction number


You want a number of for example 1000000,4 to format with thousand-grouping and two fraction numbers for the de language:

	locale = new Locale("de");
	return I18n.toString(v, "###,###.00", locale );


Caution when converting a string to a number


If you try to convert a value from getComponent(..).getValue() to number with the Number() function the XPage crashes.
The reason is that getComponent(..).getValue() returns a java.lang.string, but Number() does only work with JavaScript strings.

Use this workaround:

var v = getComponent("field").getValue();
v = new String(v);
i = Number(v);


Code about URLs


moved to Work with URLs

Changing DOCTYPE


Since 8.5.1 you can change the doctype of the rendered HTML.
See http://www.qtzar.com/blogs/qtzar.nsf/d6plinks/DSLH-834QUN
Dec's Blog">Dec's">http://www.qtzar.com/blogs/qtzar.nsf/d6plinks/DSLH-834QUNDec's Blog
See what's possible with Xpages.
Have a look at our ServiceCommunicator website
and the YouAtNotes Support.
Use  searchlotus.com  for news in the Web related to Lotus Notes and Domino,
and to search those sites.
Check  youatnotes.com  for great Lotus Notes, Domino and XPages software.
Did this wiki help you?
Did this saved you time? Express your gratitude by making a donation:
PayPal - The safer, easier way to pay online!