You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Adrian Perez Jorge <ap...@ignos.com> on 2004/01/21 20:18:36 UTC
[JXPath] Testing for null values.
Hi all!
What is the right way to test in a XPath expression if a bean property
is null?
"propertyName = false()" doesn't work because the property could be a
Boolean.
Thanks in advance,
Adrian P.J.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [JXPath] Testing for null values.
Posted by Adrian Perez Jorge <ap...@ignos.com>.
Hi!
I found in BasicTypeConverter.java the existence of "null()". So, to
check if a XPath expression yields null this code will test it
(beanshell syntax):
test = ctx.getValue("path/to/a/existent/property = null()");
But when using ctx.setLenient(true) this returns boolean false:
ctx.getValue("path/to/a/non/existent/property = null()");
which I believe it's wrong: it should be true because in lenient mode
the value of such XPath expresion when some component is null it return
null.
Comments?
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [JXPath] Testing for null values.
Posted by Adrian Perez Jorge <ap...@ignos.com>.
WTF, I was wrong. "boolean(propertyName/node())" doesn't work. By now,
I have developed a custom function test:isnull(). JXPath documentation
says type conversion from null to primitive types is false/zero, so I
believe this masks detection of a Boolean null property and maybe other
cases for other types/classes.
That's all.
Adrian Perez Jorge wrote:
> Hi again,
>
> Well, "boolean(propertyName/node())" seems to work; It will return
> Boolean.TRUE if the path exists and it's not null, and will return
> Boolean.FALSE if the path doesn't exist (lenient mode on) or the
> property is null.
>
> I need to do check that before this is evaluated:
>
> "aBeanPath/booleanProperty = false()"
>
> because if the path exists but booleanProperty is null, that
> expression will be evaluated to true().
>
> BTW if lenient mode is on and the path doesn't exist, both
> "aBeanPath/booleanProperty = false()" and "aBeanPath/booleanProperty =
> true()" will return false(). Shouldn't be this the right result when
> the path exists but the property is null?
>
> Thanks in advance.
>
> Adrian P.J.
>
> Adrian Perez Jorge wrote:
>
>> Hi all!
>>
>> What is the right way to test in a XPath expression if a bean
>> property is null?
>>
>> "propertyName = false()" doesn't work because the property could be
>> a Boolean.
>>
>> Thanks in advance,
>>
>> Adrian P.J.
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [JXPath] Testing for null values.
Posted by Adrian Perez Jorge <ap...@ignos.com>.
Hi again,
Well, "boolean(propertyName/node())" seems to work; It will return
Boolean.TRUE if the path exists and it's not null, and will return
Boolean.FALSE if the path doesn't exist (lenient mode on) or the
property is null.
I need to do check that before this is evaluated:
"aBeanPath/booleanProperty = false()"
because if the path exists but booleanProperty is null, that
expression will be evaluated to true().
BTW if lenient mode is on and the path doesn't exist, both
"aBeanPath/booleanProperty = false()" and "aBeanPath/booleanProperty =
true()" will return false(). Shouldn't be this the right result when
the path exists but the property is null?
Thanks in advance.
Adrian P.J.
Adrian Perez Jorge wrote:
> Hi all!
>
> What is the right way to test in a XPath expression if a bean
> property is null?
>
> "propertyName = false()" doesn't work because the property could be a
> Boolean.
>
> Thanks in advance,
>
> Adrian P.J.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org