0

In view, I set var in All Properties to "rowVar". Code for viewColumn.

if (!rowVar.getDocument().getItemValue("NAPAKA").isEmpty()) { return "NAPAKA"}
else {return rowVar.getColumnValue("STANJE")};

And code for this.rowClasses:

if (!rowVar.getDocument().getItemValue("NAPAKA").isEmpty())
{return "hoverCls napakaBlue";}
else{return "hoverCls";}

Former works for view with no documents, but later throws exception. Why?

Ermo
  • 91
  • 1
  • 7
  • Not sure of the exact "why" except to say that you likely need to check for null on your rowClasses. Try making the first condiditon, if(rowVar == null) then return "hoverCls", then the rest of the conditions. – Steve Zavocki Jul 15 '14 at 12:02
  • @steve, rowVar will not be created. So it will fail in anyway. However you might check the requestScope to find out, as suggested in my answer. – Serdar Basegmez Jul 15 '14 at 12:11
  • I haven't used the View Control in a while, but I believe (@SerdarBasegmez) you are correct about null checking. Good answer. – Steve Zavocki Jul 15 '14 at 12:13
  • My 2 cents: try to use value binding instead of SSJS. The view should contain column with NAPAKA field. – Frantisek Kossuth Jul 15 '14 at 12:15

2 Answers2

3

The first one belongs to the view column. So if there is no document, that will not be evaluated.

However the second one will be evaluated everytime the view is rendered. Therefore if there is no document, rowVar will not exist and your code will fail.

In your rowClasses formula, you can add a condition as the following:

if(requestScope.containsKey("rowVar") && ...(your conditions)...)

Since row is not going to be exist in anyway, null-checking will also fail.

Serdar Basegmez
  • 3,355
  • 16
  • 20
1

Serdar's answer is correct. This answer is just about efficiency.

If you are dealing with many documents in the Domino View data source, you should add the NAPAKA column to the Domino view and avoid the rowVar.getDocument() to the underlying document which in not efficient. Also, you can improve efficiency by using EL instead of SSJS. For example:

<xp:viewColumn id="viewColumn3" value="#{(empty rowVar.NAPAKA) ? rowVar.STANJE: rowVar.NAPAKA}">
     <xp:this.facets>
        <xp:viewColumnHeader xp:key="header"
           id="viewColumnHeader3" value="column header">
        </xp:viewColumnHeader>
     </xp:this.facets>
  </xp:viewColumn>