192 Lotus blogs updated hourly. Who will post next? Home | Blogs | Search | About 
 
Latest 7 Posts
Tipps and Tricks for the Java SE 8 Programmer Exam
Sun, Dec 11th 2016 7
Winning the IBM Collaboration Solutions Developer Competition 2016
Mon, Oct 3rd 2016 4
Creating ICS Calendar Feeds with XPages
Tue, Apr 12th 2016 5
3 XPages hints #3: Homepage and Performance improvements
Mon, Feb 29th 2016 8
Travelling 2.0: How your smartphone can assist you travelling easier and cheaper
Fri, Jan 15th 2016 8
Leaving the yellow bubble for a while
Sun, Jun 7th 2015 6
Simple way to make certain elements sticky in your web application (XPages example using OneUI)
Sun, Apr 19th 2015 6
Top 10
XPages: Handling disabled Checkboxes
Thu, Mar 26th 2015 9
3 XPages hints #2
Wed, Apr 30th 2014 8
Travelling 2.0: How your smartphone can assist you travelling easier and cheaper
Fri, Jan 15th 2016 8
3 XPages hints #3: Homepage and Performance improvements
Mon, Feb 29th 2016 8
Creating a test environment: the easy way
Tue, Jun 3rd 2014 7
Tipps and Tricks for the Java SE 8 Programmer Exam
Sun, Dec 11th 2016 7
Simple way to make certain elements sticky in your web application (XPages example using OneUI)
Sun, Apr 19th 2015 6
Leaving the yellow bubble for a while
Sun, Jun 7th 2015 6
My top 5 wishlist for IBM Notes / IBM Domino Designer, which ones are yours?
Wed, Aug 6th 2014 5
Get rid of the agent property “Target documents – all new & modified documents”
Tue, Jan 3rd 2012 5


3 XPages hints #2
Twitter Google+ Facebook LinkedIn Addthis Email Gmail Flipboard Reddit Tumblr WhatsApp StumbleUpon Yammer Evernote Delicious
Frederic dehedin    

I wrote the first post for some XPages tipps several months ago (5 XPages hints #1). I actually planned it to do it as a series, but soon got very involved into customer projects so i did not have the time to describe 5 tipps in detail, so i downsized it to 3. Anyway, i hope they will help ..

1. Getting the session as signer

Sometimes you need to get document information (e.g. for a website) with higher access rights, than the logged-in user (or “Anonymous”). For this case, you can get a session as the signer of the design element(s). In the traditional Domino Web Development world, this would be the agent property “run as webuser” disabled. Here is the code for it (normally placed as a static method):

public static Session getSessionAsSigner() {
	Session sessionAsSigner = null;
	try {
		FacesContext context = JSFUtil.getFacesContext();
		sessionAsSigner = (Session) context.getApplication()
				.getVariableResolver().resolveVariable(context,
					"sessionAsSigner");
	} catch (Exception e) {
		Util.logError(e);
	}
	return sessionAsSigner;
}

Danger
You have to sign all the according design elements with the same ID, otherwise you may get some unexpected results.

 

2. Getting results of a called agent from an XPage

We had a pretty old Domino Application (R6.5), for which we had to renew the Web Browser UI, so we decided to do it with XPages. Since many of the business logic is already written in Lotusscript Agents and Script Libraries, we tried to use the existing (and tested) code as much as possible. Starting a Lotusscript agent from an XPage is easy, but to know what this agent was actually doing or getting the results of that agent is a little bit more tricky. For example you want to know how many documents the agent changed and display it in the XPages user interface. In our case we had to validate a reservation document with an existing lotusscript function, so when validation fails, the document is not saved.. For techniques like this, the following technique comes in handy:

–> We actually pass the “in memory” document to the agent. This can be an existing, unsaved document, or a completely new one..

//getting the agent
Agent agent = app.getDb().getAgent("(AGENTNAME)");
//start the agent with the document as parameter
agent.runWithDocumentContext(doc);

//the agent writes his results into a field names "tmpReturnValue"
//in this case writes "1", if the validation succeeded.. if the agent failed, or the values of the documents are not valid, then the validation turns out false..
String agentResult = doc.getItemValueString("tmpReturnValue");

if (agentResult.equals("1")) {
	result = true;
} else {
	result = false;
}
//we don't need the result of the agent to be saved in the doc, so we remove the item..
doc.removeItem("tmpReturnValue");
  • doc: This is the Document Object, resolved with the current datasources backend document. This could be also a newly created document from scratch within this method..
  • app.getDb(): app is my session bean, which i use to get DBs, Views, etc.

In the Lotusscript agent you can get the document and validate the entered values like this:

Dim s As New NotesSession
Dim doc as notesdocument
Set doc = s.Documentcontext

if validateSomething(doc) then
	Call doc.Replaceitemvalue("tmpReturnValue", "1")
end if

 

3. Creating an ICS Calendar feed

We had a request to create an ICS Calendar feed to download. We decided to use biweekly (http://sourceforge.net/projects/biweekly/) and are pretty happy with it. First we need a managed bean from which we can call a function like this:

public String getIcsFeed(){
String result = "";
try {

ICalendar ical = new ICalendar();

ical.setProductId("-//My Feed");
VEvent event = new VEvent();
event.setSummary("Hungergames");
event.setLocation("TheArena, 860345 Capitol");
event.setOrganizer("Capitol");
event.setDateStart(new Date());
event.setDateEnd(new Date());
ical.addEvent(event);

result = ical.write();

} catch (Exception e) {
Util.logError(e);
}
return result;
}

In a real life situation, you would loop through some events, and then add the events to the ical object..

You can then call this function in an XPage like this:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" rendered="false">
<xp:this.afterRenderResponse><![CDATA[#{javascript:var externalContext = facesContext.getExternalContext();
var writer = facesContext.getResponseWriter();
var response = externalContext.getResponse();
response.setContentType("text/ics");
response.setHeader("Cache-Control", "no-cache");
writer.write(managedBean.getIcsFeed());
writer.endDocument();}]]></xp:this.afterRenderResponse>
</xp:view>

Hope this tipps can help you..



---------------------
http://www.fdehedin.ch/299/5-xpages-tipps-2
Apr 30, 2014
9 hits



Recent Blog Posts
7
Tipps and Tricks for the Java SE 8 Programmer Exam
Sun, Dec 11th 2016 4:17p   Frederic Dehedin
Recently i studied for the Java SE 8 Programmer I Exam (Java OCA for short) and was glad that i passed it on the first go. Although i’ve been practicing programming in Java several years, i decided to sustain my practical knowledge with some theoretical background and i’m happy to share my experience in this blog […]
4
Winning the IBM Collaboration Solutions Developer Competition 2016
Mon, Oct 3rd 2016 12:23p   Frederic Dehedin
Just yesterday we came back to Switzerland after our 3 Weeks holidays in Indonesia. We were in Bali, Nusa Lembongan (Island next to Bali) and Rote Island (Timor). So on the 16. September 2016, after a beautiful day on the boat diving with Manta Rays, i was eager to check the contest results and received […]
5
Creating ICS Calendar Feeds with XPages
Tue, Apr 12th 2016 8:52a   Frederic Dehedin
An ICS Calendar feed can be used to exchange calendar data over the internet. It’s also known as iCalendar feed. ICS Calendar Feeds are supported by a vast amount of calendar clients such as Google Kalender / Android Kalender, Microsoft Outlook.. and of course IBM Notes. The main benefit is to provide calendar data in an open standard format, […]
8
3 XPages hints #3: Homepage and Performance improvements
Mon, Feb 29th 2016 2:37a   Frederic Dehedin
Finally another blog post hope these 3 hints will help you or will help you some day in the future. In this series of XPages hints i included also a NSF File in which the described hints are implemented. But beware, it is not a design highlight i wanted to keep it as simple as possible. The Extension Library is needed to run the examples (from openntf.org or the included version in Domino 9.x). Hint 1: Always define a home page Usually every applicatino has 1 point of entry, a homepage. This




Created and Maintained by Yancy Lent - About - Planet Lotus Blog - Advertising - Mobile Edition