PostProcessor doesn't get called if field value is not set

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

PostProcessor doesn't get called if field value is not set

richardlhr
Hi,

I created an annotation to set a field default value and a postprocessor that would check for null and return the default value from the annotation.
However it seems the postprocessor is only called if the field value is not null, defeating my attempt at returning a default value.

What would be the right way to implement something like this?

@Default("mydefault")
@JcrProperty("zbm:option")
private String myfield;

By the way, it would be awesome to have this out of the box in Slice.
Reply | Threaded
Open this post in threaded view
|

Re: PostProcessor doesn't get called if field value is not set

maciej.majchrzak
Administrator
Hi,

You can achieve this by using postprocessors. Postprocessors work the same way as preprocessors and are always invoked for a field. However, whether a postprocessor's "processValue" is called depends on a result of its "accepts" method. Make sure you implement it according to desired logic - in your case you should probably accept cases where value is not set on a field.

Support for default options is in our backlog but since it breaks a contract it will be done in Slice 5 release.

Cheers
Maciej
Reply | Threaded
Open this post in threaded view
|

Re: PostProcessor doesn't get called if field value is not set

richardlhr
My accept method wasn't right. Everything works fine now.