Social Icons

twitterfacebookgoogle pluslinkedinrss feedemail

Pages

Tuesday, March 15, 2011

XPages - Difference between xp:this.data (xp:dominoView) and xp:dataContext usage?

One of the useful thing I learnt at a quick glance over the book ("Mastering XPages") so far is the dataContext. In fact, I was thinking how can some complex computation be done in one place in the XPage and then reference that computed object anywhere else in the page. dataContext is just what I needed.

Now that I use it extensively in my code, I kind of started thinking that the xp:this.data is also almost like a dataContext. (I may be totally wrong, but then I need someone to tell me that). And I had to use the xp:dominoView and a dataContext variable as the value of a repeat control conditionally. You might be wondering, what made me think to do something like that. Here is the story.

I have built a re-usable custom control (using xp:dominoView as the repeat control value) and I needed to implement a search inside the single category. I know that the search will just ignore the “categoryFilter” or the “keys”. Then the only way for me is to add the single category as a part of the view search query. Unfortunately, the single category column is complex and it is hard to come up with a generalized search syntax.

That’s when I thought of using a dataContext like the following as the repeat control value when the search is on.


            <xp:dataContext var="dcSearchResults">
                  <xp:this.value><![CDATA[#{javascript:var db:NotesDatabase=session.getDatabase("","")
db.openByReplicaID(sServerName, sReplicaID );
var vw=db.getView("view1");
var dc=vw.getAllDocumentsByKey("key1");
return dc.FTSearch("some query"); /*Code not tested*/
}]]></xp:this.value>
            </xp:dataContext>
</xp:this.dataContexts>

The dominoView is defined like the following.

  
      <xp:this.data>
            <xp:dominoView var="dominoView"
                  categoryFilter="#{javascript:compositeData.SingleCategory}"
                  databaseName="#{javascript:compositeData.Database}"
                  viewName="#{javascript:compositeData.ViewName}">
            </xp:dominoView>
      </xp:this.data>


The repeat control value was originally the following.


      <xp:repeat var="ViewEntry" disableTheme="true" id="rptViewBody"
                  value="#{dominoView}">


The value is modified as the following so that depending on if the search is on/off, the repeat control will get a different array to loop through. The search result rows displayed correctly when search was on, but as feared the dominoView didn’t display any rows when search was off.


      <xp:repeat var="ViewEntry" disableTheme="true" id="rptViewBody"
                  value="#{javascript:isSearchOn()!=true?dominoView:dcSearchResults}">


So, it appears that the xp:dominoView cannot be mixed with other code like a dataContext. It has to be a simple “#{dominoView}” or “#{javascript:dominoView}” (dominoView is the name of the variable).

Or am I missing something here? (I have posted this question on the xpages forum too.)

0 comments:

Post a Comment