Vince's xwork log

About software and other stuff






xAgents, xAgents everywhere....

I am currently working on several concurring development projects and I noticed that the focus is shifting from creating 'pure' xPage documents to xAgents (an xPage set to behave like an agent) to replace 'webagents' used for WebQueryOpen, WebQuerySave or Ajax events.
The 'old' functionality was written in either LotusScript agents, Java agents or Servlets.
The reason for converting the 'webagents' to 'xAgents' is that they offer more performance than LS agents, are more stable than Java agents and easier to deploy and maintain than servlets.
Especially the move from java agents to xAgents is very easy, even if you don't use xPages anywhere else in your application.

1. Create a new xPage, set rendered to "false" and copy your java code in it.
2. Change the current 'PrintWriter' to 'ResponseWriter' like this:

// get the response and set header info
var response = facesContext.getExternalContext().getResponse();;
response.setContentType("application/json");
response.setHeader("Cache-Control", "no-cache");
// get the output writer and print the data
var pageOut = facesContext.getResponseWriter();
pageOut.write("{'jsonvar'='jsonvalue'");
pageOut.endDocument();
pageOut.close();
facesContext.responseComplete();

3. If you have supporting classes put them in the 'code/Java' section
4. Change the calls to the agent to your new xAgent and you should be good to go :)

P.S. Does not work on pre 8.5 Domino versions ;)