Getting To The Java Roots of XPages – Part 4

So in the previous part we wrote our first bit of java code, a method ( getMyInternetAddress) in a class ( AboutMe ) in a package ( scary.java.demo ). So the question remains, how do I actually use that in my XPage applications?

So remember that link that had a big ssjs code block in it? To use the new java code instead you can just replace the ssjs with a single line that reads

scary.java.demo.AboutMe().getMyInternetAddress()

and the xpage can be saved and previewed and it will do the exact same as what the long ssjs version did. The generated java for the page now looks like this

XspOutputLink result = new XspOutputLink();
result.setValue("/myOtherPage.xsp");
result.setEscape(true);
setId(result, "link1");
String sourceId = "link1/@text";
String textExpr = "#{javascript:scary.java.demo.AboutMe().getMyInternetAddress()}";
ValueBinding text = evaluator.createValueBinding(result, textExpr, sourceId,String.class);
result.setValueBinding("text", text);
return result;

You will notice that I’m still using ssjs and the resulting java still uses this ValueBinding concept to run the ssjs at runtime. While there are ways to avoid ssjs totally ( which I’ll explain in upcoming parts ) this is actually a tiny little bit better then before because your scary.java.demo.AboutMe class already compiled and optimized by the compiler, meaning it runs much faster then the long ssjs version.

Wouldn’t it be much better if I could get rid of the ssjs entirely? I’ll look at this in the next few parts but next we need to talk about another scary word, Beans…

Advertisement
Tagged with: ,
Posted in None
Archives
%d bloggers like this: