You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Veit Guna <ve...@gmx.de> on 2017/12/06 22:26:28 UTC
strict mode but ignore null
Hi.
I would like to setup Velocity so that invalid (=unknown)
properties/methods are throwing an exception, but null values shouldn't.
And that per default.
I know that I could use quiet references, but I would have to think
about everytime, whether it could be null or not. Or use it all the time,
which I would like to avoid - since I'm lazy :).
I activated strict mode which fails on unknown properties/methods -
which is good.
But it also fails on something like
$valid.nullPropertyToObject.validproperty
What I would like is, that it doesn't fail because of
nullPropertyToObject being null.
My basic idea around this is, to spot real errors like unknown
properties during tests.
I don't really care about actual null values/references - these should
be rendered empty in case of null during runtime.
In my tests I assert, that the rendering basically works (all
properties/methods exist) and values are properly filled.
But I don't want (ever) to fail only because one property is null during
runtime.
Is this somehow possible?
I just upgraded to 2.0 hoping that this is handled more flexible now.
Cheers
Veit
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: strict mode but ignore null
Posted by Veit Guna <ve...@gmx.de>.
Yeah, I just started to disable the strict mode and use
InvalidReference- and ReferenceInsertingHandler. Let's see how this
works out.
Thanks for your feedback guys!
Am 07.12.2017 um 16:19 schrieb Alex Fedotov:
> I am guessing that you can also install a reference insert handler in your
> setup and handle null values there as needed.
>
> Alex
>
>
> On Thu, Dec 7, 2017 at 9:35 AM, Claude Brisson <cl...@renegat.net.invalid>
> wrote:
>
>> I looked at the code, and, well, it looks like the strict mode is ...
>> rather strict. Even quiet references will throw an exception if you try to
>> access a property on a null object.
>>
>> The only thing you can do to circumvent the exception is wrapping the
>> property use in #if() statements :
>>
>> #if($nullobj) $nullobj.someProp #end
>>
>>
>> Claude
>>
>>
>>
>> On 06/12/2017 23:26, Veit Guna wrote:
>>
>>> Hi.
>>>
>>> I would like to setup Velocity so that invalid (=unknown)
>>> properties/methods are throwing an exception, but null values shouldn't.
>>> And that per default.
>>> I know that I could use quiet references, but I would have to think
>>> about everytime, whether it could be null or not. Or use it all the time,
>>> which I would like to avoid - since I'm lazy :).
>>>
>>> I activated strict mode which fails on unknown properties/methods -
>>> which is good.
>>>
>>> But it also fails on something like
>>>
>>> $valid.nullPropertyToObject.validproperty
>>>
>>> What I would like is, that it doesn't fail because of
>>> nullPropertyToObject being null.
>>>
>>> My basic idea around this is, to spot real errors like unknown
>>> properties during tests.
>>> I don't really care about actual null values/references - these should
>>> be rendered empty in case of null during runtime.
>>>
>>> In my tests I assert, that the rendering basically works (all
>>> properties/methods exist) and values are properly filled.
>>> But I don't want (ever) to fail only because one property is null during
>>> runtime.
>>>
>>> Is this somehow possible?
>>>
>>> I just upgraded to 2.0 hoping that this is handled more flexible now.
>>>
>>> Cheers
>>> Veit
>>>
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>>> For additional commands, e-mail: user-help@velocity.apache.org
>>>
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: user-help@velocity.apache.org
>>
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: strict mode but ignore null
Posted by Alex Fedotov <al...@kayak.com>.
I am guessing that you can also install a reference insert handler in your
setup and handle null values there as needed.
Alex
On Thu, Dec 7, 2017 at 9:35 AM, Claude Brisson <cl...@renegat.net.invalid>
wrote:
> I looked at the code, and, well, it looks like the strict mode is ...
> rather strict. Even quiet references will throw an exception if you try to
> access a property on a null object.
>
> The only thing you can do to circumvent the exception is wrapping the
> property use in #if() statements :
>
> #if($nullobj) $nullobj.someProp #end
>
>
> Claude
>
>
>
> On 06/12/2017 23:26, Veit Guna wrote:
>
>> Hi.
>>
>> I would like to setup Velocity so that invalid (=unknown)
>> properties/methods are throwing an exception, but null values shouldn't.
>> And that per default.
>> I know that I could use quiet references, but I would have to think
>> about everytime, whether it could be null or not. Or use it all the time,
>> which I would like to avoid - since I'm lazy :).
>>
>> I activated strict mode which fails on unknown properties/methods -
>> which is good.
>>
>> But it also fails on something like
>>
>> $valid.nullPropertyToObject.validproperty
>>
>> What I would like is, that it doesn't fail because of
>> nullPropertyToObject being null.
>>
>> My basic idea around this is, to spot real errors like unknown
>> properties during tests.
>> I don't really care about actual null values/references - these should
>> be rendered empty in case of null during runtime.
>>
>> In my tests I assert, that the rendering basically works (all
>> properties/methods exist) and values are properly filled.
>> But I don't want (ever) to fail only because one property is null during
>> runtime.
>>
>> Is this somehow possible?
>>
>> I just upgraded to 2.0 hoping that this is handled more flexible now.
>>
>> Cheers
>> Veit
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: user-help@velocity.apache.org
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>
Re: strict mode but ignore null
Posted by Claude Brisson <cl...@renegat.net.INVALID>.
I looked at the code, and, well, it looks like the strict mode is ...
rather strict. Even quiet references will throw an exception if you try
to access a property on a null object.
The only thing you can do to circumvent the exception is wrapping the
property use in #if() statements :
#if($nullobj) $nullobj.someProp #end
Claude
On 06/12/2017 23:26, Veit Guna wrote:
> Hi.
>
> I would like to setup Velocity so that invalid (=unknown)
> properties/methods are throwing an exception, but null values shouldn't.
> And that per default.
> I know that I could use quiet references, but I would have to think
> about everytime, whether it could be null or not. Or use it all the time,
> which I would like to avoid - since I'm lazy :).
>
> I activated strict mode which fails on unknown properties/methods -
> which is good.
>
> But it also fails on something like
>
> $valid.nullPropertyToObject.validproperty
>
> What I would like is, that it doesn't fail because of
> nullPropertyToObject being null.
>
> My basic idea around this is, to spot real errors like unknown
> properties during tests.
> I don't really care about actual null values/references - these should
> be rendered empty in case of null during runtime.
>
> In my tests I assert, that the rendering basically works (all
> properties/methods exist) and values are properly filled.
> But I don't want (ever) to fail only because one property is null during
> runtime.
>
> Is this somehow possible?
>
> I just upgraded to 2.0 hoping that this is handled more flexible now.
>
> Cheers
> Veit
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org