I have a view panel where I want to style the color the of text in the row based on a value in the document.
<xp:viewPanel id="dataView1" var="rowData" rows="5"
rowClasses="#{javascript:rowData.getColumnValue('objectStatus') == 'Inactive' ? 'status-inactive' : ''}">
This works perfectly fine if the view has at least one document, but if the view is empty I get the following error:
com.ibm.xsp.exception.EvaluationExceptionEx: Error while executing JavaScript computed expression
Error while executing JavaScript computed expression
Script interpreter error, line=1, col=10: [ReferenceError] 'rowData' not found
I'm guessing it has something to do with rowData
not being created unless a document exist, but I can't figure out how to check for it.
I tried if (rowData != null)
and !@IsNull(rowData)
but I still get the same error.
How do I solve this problem?
(Note that I am late to the XPages game.)
EDIT:
Thanks to all for the input but I was able to solve the issue by simply checking the view count:
if (getComponent('dataView1').getRowCount() > 0) {
'Inactive'.equals(rowData.getColumnValue('objectStatus')) ? 'status-inactive' : ''
}
EDIT 2:
Knut has a slightly quicker solution so I gave him credit.
You can test it with if (typeof rowData !== 'undefined') ...
.
If the view is empty then rowData is 'undefined'.
<xp:viewPanel id="viewPanel1" var="rowData" rows="5"
rowClasses="#{javascript:
if (typeof rowData !== 'undefined')
rowData.getColumnValue('objectStatus') == 'Inactive' ? 'status-inactive' : ''
}">
(This solution is probably some ms faster than .getRowCount() :-) )