$sys.item.hasProperty() always returns false

$sys.item.hasProperty() is always returning false even when a field does exist in the content type?

Is this a bug and is anyone else havingthis issue in Rx 6.7.0 Build 200906P01 (3222) [RX-15938]?

Does the field you are checking have a value? If not, this is the expected behavior of $sys.item.hasProperty(). I opened a ticket a year ago related to the same thing. The behavior of $sys.item.hasProperty() as I understand it is…

Lets assume we have a field called “title” in our content type.

Condition -> Result
If the content type contains the field and no value is set -> false
If the content type contains the field and a value is set -> true
If the content type does not contain the field -> false


This is a good question.

How does one check whether a property is available to $sys.item?


My sentiments exactly.

According to the javadocs in Rhythmyx/Docs/javadocs:

Node’s method (can be used against $sys.item):

public boolean hasProperty(java.lang.String relPath) throws RepositoryException
Indicates whether a property exists at relPath Returns true if a property exists at relPath and false otherwise.
Returns: true if a property exists at relPath; false otherwise.

I can’t find it in the javadocs, but I know that you can use the isEmpty() method on a property to determine if it has no value.

For example, in the BinaryIsValid template I posted in code snippets (for inline image previews in content editors), I use the following code:

#if( $isValid.hasProperty("rx:${submitname}_height") && !$isValid.getProperty("rx:${submitname}_height").[B]isEmpty[/B]() )

That both of these methods exist seems to imply that what 'myx master say may not be entirely accurate. And that my template only throws errors when it hasn’t been added to the content type whose editor you’re viewing, it seems to imply that either my conditions are redundant, or they are both working as implied/intended.

Can anyone from percussion give a ruling on this?

I have retested my results as I gave in my original post and they are the same. Even the definition from the JavaDocs for hasProperty supports them. I think the real problem here is how misleading hasProperty() is. One would assume that if the editor for an item contained a field to enter a value for property “X” then that item should haveProperty() “X” :slight_smile: However this simply is not the case. An item seems to have a property only when it is associated with an item and has a value ( thus hasProperty() returns true ), otherwise it returns false.

As a side note I am willing to change 'myx master to 'myx misinformed… :slight_smile:

Can somebody from Percussion make a final call here?

I have requested a senior resource take a look at this thread and respond accordingly. A response will be forthcoming.

The original post is correct. IPSNode.hasProperty() will return true if the property exists AND it has a value. It is false otherwise.

Remember that the Node and Property interfaces (and their Javadoc) are part of the JCR standard. We (Percussion) can’t change them, we just implement (and in some cases, extend them).

The easiest way to determine if a Property is null is to call the isNull() method. (I don’t see an isEmpty() method on the implementation classes, but that doesn’t mean it doesn’t exist in one of wrapper classes).

If you need to differentiate between “not defined” and “no value”, call IPSProperty myProperty = IPSNode.getProperty(). If myProperty == null, then the property is not defined. If myProperty.isNull() is true, then the property is defined but has no value.

You can also use the PSItemDefManager to load the PSItemDefinition. Calling itemDefinition.isFieldExists(name) will tell you if the field is defined for the content type.

I hope this clears things up.


While searching for a method to access PSItemDefManager from a velocity template (at which I ultimately failed), I came across this method for Determining if a content item has a specific property available.

This should suffice for your purposes.