Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

AEM 6.5 Navigation Core Component throws Sigthly Exception Operands are not of the same type: comparison is supported for Number types only.

Avatar

Level 2

I have to display the navigation items based on user entity tags. So i have decided to extend the Core component Navigation model and  filter those results. 

But i get this error with the core Navigation component. I believe the error is in the below line

data-sly-test.hascontent="${navigation.items.size > 0}"

 

Any suggestions or fixes?

 

Stacktrace:

 

Caused by: org.apache.sling.scripting.sightly.compiler.SightlyCompilerException: Operands are not of the same type: comparison is supported for Number types only.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@ArchR 

Below code should not be the issue. But check if navidation.items.size is returning numeric 

data-sly-test.hascontent="${navigation.items.size > 0}" 

 

And also check your Sightly script for any comparisons being made between non-numeric values, such as strings or booleans. You should ensure that both operands are numeric values before attempting to compare them.

 

If you are comparing variables or properties, you should also make sure that their values are being correctly assigned and are of the expected type. You may need to explicitly cast or convert the values to the correct type before making the comparison.

View solution in original post

4 Replies

Avatar

Community Advisor

Hi,
The Sightly block statement you shared

data-sly-test.hasContent="${navigation.items.size > 0}"

 should not throw any error ideally because it is a part of navigation.html.

can you share the complete stack trace? and if possible share a few more details as in if how you've customized it.

Avatar

Community Advisor

Hi @ArchR ,

 

The issue must be with the extended model. You need to debug the Sling Model and check if while filtering the items are coming zero or some other unexpected behavior. Just check the size of items in Sling Model while debugging.

 

Thanks,

Ritesh Mittal

Avatar

Level 6

Hi @ArchR ,

 

Looks like, the error is in code, at a location where "Less or equal" comparison is happening as the error below mentions LEQ and not GT (greater than) binary operator.

 

at org.apache.sling.scripting.sightly.compiler.expression.nodes.BinaryOperator.leq(BinaryOperator.java:214) [org.apache.sling.scripting.sightly.compiler:1.1.2.1_4_0]

 

Do you happen to have any "<=" comparisons in your extended code?

 

Thanks,

Ram

Avatar

Correct answer by
Community Advisor

@ArchR 

Below code should not be the issue. But check if navidation.items.size is returning numeric 

data-sly-test.hascontent="${navigation.items.size > 0}" 

 

And also check your Sightly script for any comparisons being made between non-numeric values, such as strings or booleans. You should ensure that both operands are numeric values before attempting to compare them.

 

If you are comparing variables or properties, you should also make sure that their values are being correctly assigned and are of the expected type. You may need to explicitly cast or convert the values to the correct type before making the comparison.