GETメソッドのパラメータからxPageの挙動をコントロールする方法

他のページからジャンプしてきた時に、xPageの表示内容を変更したい時などに役立つ知識だと思います。

引用元のブログではGETメソッドのパラメータを使って表示するカテゴリのフィルタリングを行っています。

What this code does is before the page has loaded it looks at the URL and finds the location= part and if it exists it puts whatever the value is into a sessionscope variable called 'locationfilter'. Session Scope is a special scope where you can add variables that only last for the duration of the users session. As soon as they close their web browser the session scope variables are lost. There is also an Application Scope and a Page Scope that you can use to store these values. Heres how the code will look in the source view of your xpage, you can see the resource for the server side script library and the beforePageLoad script. As you get more advanced in XPages you may find yourself writing code directly in the source view.

引用元: Dec's Dom Blog :: Learning XPages Part 20 : Restricting The Repeat To A Single Category.

実際、GETメソッドのパラメータをbeforePageLoadイベントでチェックするのに

var cgi = new CGIVariables();
var param = cgi.getURLParam("Location");
if (param) {
if (param != "" )
sessionScope.locationfilter = param;
}

引用元: Dec's Dom Blog :: Learning XPages Part 20 : Restricting The Repeat To A Single Category.

というサンプルコードがあるのですが、Louts Notes/Domino 8.5に付属してくるディスカッションテンプレートにあるxpCGIVariables Script Libraryではcgi.getURLParam()というファンクションがないため上手く動きません。

そこで、taskjam.netからTaskJam V1.0とうテンプレートをダウンロードしてもってきます。

ここで、とても興味深かったのが、ブログで寄せられているコメントなんですが、

There is also a MUCH easier way to get the parameter instead of including the script library (although it's probably good that you showed that).

Use the global "context" JavaScript object:
context.getUrlParameter("Location")

という書き込みがあり、「context.getUrlParameter("Location")を使うともっと簡単にパラメータが取ってこれるよ」、と言っています。

で、ブロガーのDec自身が

I was thinking the exact same thing but have come to realise over the past couple of days that context.getUrlParameter() is not available in certain contexts, such as described above, and when programmatically getting the document id.

と返事してます。

実は自分も同じように

context.getUrlParameter("Location")

beforePageLoadイベントで使おうとしたんですが、なぜか値を取得しなくて、調べている内に彼のブログに辿り着きました。

興味ある方は、TaskJam V1.0テンプレートのxpCGIVariablesを覗いて頂ければ分かるとおもうのですが、

自分の結論としてはbeforePageLoadイベントでは

context.getUrlParameter()

はまだ値が格納されておらず、

facesContext.getExternalContext().getRequest()

には格納されている。

ということにしておきました :-)(自分はIBMの人間じゃないので間違っている可能性大です><)

さらに突っ込むと、同じコメント欄で

パラメータを渡すようなことをしなくてもリンク元でsessionScopeを使って予め設定しておけばいいんじゃないの?

というコメントも寄せられていて、

実際、自分もそれをまず試したのですが、結論としては(自分の環境では)動きませんでした。

リンクが同じデータベース内にあって、リンクをクリックされたとき、onclickイベントなどでsessionScopeを使って値を設定する場合は、正常に動作するとおもうのですが、

自分の場合は、他のデータベースに貼ってあるリンクからジャンプさせていたので、onclickイベントでsessionScopeの値を設定しても、リンク先のデータベースではsessionScopeの値を取得出来ませんでした。

ここで、悩んだのが、sessionScopeっていったい、どこの保存されているのか?

これも、自分の憶測と断って書かせてもらうと、

sessionScopeはUserがログインしている間保存されるが、その値自体は、定義したデータベースが持つ。なので、2つのデータベースで同じ変数のsessionScopeの値が違うということはありえる。

ということです。 検証しようと思えば簡単なので、時間が出来たときにやってみたいと思います。もしくは答えを知っているかたがおられたら教えてください(><)


Lotus Notes 8.5.1のためLotus Expeditor ToolkitをEclipseに設定する時の注意点

Lotus Notes 8.5.1の埋め込みブラウザをSSO(Single-Sign-On)対応させるために、Lotus Expeditor Toolkitを使ったEclipseの設定をしようとしたのですが、Lotus Notes 8.5.1のVMが見当たらないので、ググッてみると以下のように構造に変更があったみたいです。

There's no longer a JRE stored in the plugin directory way down in the directory structure. Now you simply use the JVM in /jvm - simple right?!

This is nice but it means that your Eclipse configuration needs to be a little different JVM wise. I have therefore updated my Eclipse configuration guidelines to work with Notes 8.5.1.

引用元: Configure Eclipse 3.4 for Notes 8.5.1 - lekkimworld.com.

以前は、

<Notes install dir>/framework/rcp/eclipse/plugins/com.ibm.rcp.j2se.win32.x86_1.5.0.SR4-200707311521/jre

などとなっていたのですが、Lotus Notes 8.5.1では引用元の紹介にもあるように、

<Notes install dir>/jvm

に変更になっていました。
詳しくは Eclipse configuration guidelines to work with Notes 8.5.1に書いてあります。

これは、自分の設定した場合、

Lotus Notes 8.5.1 VM

なお、Lotus Expeditor Toolkitの設定自体は以下のリンク等にかいてあるのが参考になるとおもいます。

http://www.ibm.com/developerworks/lotus/library/expeditor-notes-sametime/
http://www.ibm.com/developerworks/lotus/library/expeditor-browser/


Notes ClientでxPageをオープンするための?OpenXPages

前回の投稿に続き、Lotus Notes 8.5.1からxPagesをComposite ApplicationにComponentsとして追加できる機能がついたので、早速試してみたのですが、Dblookupで他のデータベースからドキュメント情報を取得することは出来るけど、いざ、そのドキュメントをオープンさせようとしたときに、上手いこといかない、という問題に躓いたので記しておきます。

実際、なにが上手いこと行かなかったかというと、

  1. http:// のプロトコルでリンクを手前で生成しているような場合に、Lotus NotesはWebブラウザで開けようとするが、認証をもう一度求められてしまう。
  2. リンクを参照パスにしても、Proxyエラーや、404エラーとなってしまって開くことが出来ない。

で、どうするのかな~と思い調べてみると、答えはxPagesのブログに有りました。

?OpenXPage has been added as a supported parameters for the notes:// protocol to launch an XPage in the Notes client.

引用元: What's New For XPages in 8.5.1 - XPages Blog - The XPages Blog.

Lotus Notes 8.5.1 のxPagesの新しい機能紹介の投稿なんですが、

Notes ClientでxPageをランチするために notes:// プロトコルの?OpenXPages というパラメータをサポートしました。

ということらしいので、自分の探していたのはこれかも?!と思い試してみたら見事に動きました。

自分の例では、

Link Core ControlのOptionsで「Link type」を「URL」にして、以下のようなComputed Valueで上手くいきました。

return "Notes:///88257656006337D3/content.xsp?OpenXPage"

余談ですがxPagesをComposite ApplicationのComponentとして使いたい場合は、極力xPagesで用意されたCore Controls等を使って作っていくのが近道っぽいです。もちろんThemeなども。

自分はxPagesのSourceタブからhtmlコードやCSSファイルをガツガツ埋め込んでいっていたので、Componentにしたとき、ほとんど動かず、結局かなり作り直すはめになっちゃいました・・・(涙)

追記:12月16日2009年
Domino Designere URLs for xPgages というエントリーがDomino Designer Wikiに追加されてます。

http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Domino_Designer_URLs_for_XPages


xPages Component(Notes 8.5.1)でDblookup()使用時の注意点

xPages Componentを使ってLotus Notes Client 8.5.1上でxPagesを表示させる新しい機能を試したときに、自分のxPagesを以下のようにチューニングしないと上手く動かなかったので、注意が必要になります。

症状

xPagesをブラウザで見るとうまく表示されるのに、Notes Clientで見るとDblookup()でエラーが発生する。

状況

サーバのComposite Applicationを直接開いたときにエラーが発生するが、ローカルレプリカを開いたときは発生しない。

原因

@Dblookup()の1st パラメータの dbName が正しく設定されていなかった。

詳細

以下のコードではDblookup()が正常に値を返しません。

<![CDATA[#{javascript:var db = ["" ,"folder/cms.nsf"];
var viewName = "(vwTestLookup)";
var key ="Keyword";
var value = "";
var value = @DbLookup( db , viewName , key , 6 );
var retValue = "";
if(!@IsError(value)){
for( var i=0; i< value.length && i < maxEntry; i++){
retValue += "<li>"+value[i]+"</li>";
}
}
else{
retValue = "Error happened in DbLookup(). ";
}
return "<ul>"+retValue+"</ul>";}]]>

原因は一行目の

var db = ["" ,"folder/cms.nsf"];

にありました。 Webブラウザから見る場合はサーバ自身のfolder/cms.nsf データベースを参照してくれるので、問題なく期待した動作をするのですが、Notes Clientで開くと、ローカルPCのfolder/cms.nsfを参照しにいってしまうため、レプリケーションがない環境ではエラーが発生してしまいます。

対処法

Dblookup() のdbName Arrayの 1st elementにサーバネームを渡すようにする。

var db = [database.getServer() ,"folder/cms.nsf"];

としてやれば、どちらも動くようになります。

ちなみに、xPages Componentと同じDBを参照する場合は、

var db = @DbName();

としてやるだけでOKです。

複雑な処理をしている既存のxPagesをComponentで動かす言った場合、このようなケースではただエラーが発生するので、丁寧なコードを書いていないとデバッグ作業は思いのほか時間がかかってしまいます。


どのフォルダにドキュメントが格納されているかを知る @WhichFolders

自分の使っているLotus Notes 8.5.1のメールで「All Documents」にフォルダ情報が表示されているのが不思議で、Designerで($All) view を開いてみたら「Folder」columnに@WhichFolders ってのが記載されていました。

@WhichFoldersなんて便利なコマンドあったっけ?と思ってググってみました。

Knowing which folder a document is in - @WhichFolders

Steve Castledine 8 September 2008 09:28:53

Sometimes people don't see the release notes (I'm not saying this is definitely in them), or new formula etc can be forgotten, but a nice new formula in 8.5 was @WhichFolders which can be used to determine, surprisingly, which folder the current document is in.

To see it in action, it was added to the mail template, all documents view.

Funny, I'm not even sure this made it into the designer help db, I will have to check.

引用元: Knowing which folder a document is in - @WhichFolders.

Lotus Notes 8.5から出来たFormula だったんですね。
しかもドキュメントにはなっていないみたい。 隠しコマンド?

ちなみに、@WhichFolders を調べているときに発見した別のブログ「Interesting undocumented formulas」( http://lotus-blogs.blogspot.com/2009/01/interesting-and-undocumented-formulas.html )

にもいろいろと紹介されています。

さて、こんな便利なコマンドが@Formulaには用意されたみたいなんですが、自分への命題は「Lotus Notes C API」を使って同等の機能を実装できるか?

これが、簡単なようで上手くいかない。 IMAPコマンドをメールDBに対して掛けてやると$FolderRefが埋め込まれるのでこれによってフォルダ階層を割り出すことが可能になるのだが、もうちょっとスマートな方法を模索中・・・

と、またまた、ためにならない投げっぱなしな投稿でおわり。