# Issue with If validation

MartVq
35 2

Hello, been at this for quite some time now and really do not know what else to try or how to explain this. Seem to be having an issue with if statement calling a method inside the viewmodel class.

My initial attempt was to use this (ps tried zul namespace too):

<xh:a autodisable="self" href="${c:cat('/auth/reorder/', intService.id)}" sclass="btn btn-primary" if="@load(vm.reorder(intService))" disabled="@load(vm.isDisableOrder(intService))">${cf:l("service.order")}
</xh:a>


In particular here issue is with vm.reorder(intService) expression - no method is being called when looking through debug and it seems to validate to false by default. And what makes it more curious is the fact that vm.isDisableOrder(intService) is actually being called and works just fine.

Then i tried this:

<xh:a autodisable="self" href="${c:cat('/auth/reorder/', intService.id)}" sclass="btn btn-primary" if="${vm.reorder(intService)}"
${cf:l("service.order")} </xh:a>  In this case the method is called, but parameter is always null (except when passing primitives like boolean). Here is a method, though now changed to simple return of true to make it easier to troubleshoot: public boolean reorder(ServiceView service) { return true; }  delete retag edit ## 1 Answer Sort by » oldest newest most voted answered 2021-08-24 12:19:36 +0800 cor3000 6094 2 7 I assume the detail you're unaware of is that the if-attribute is a special ZUML attribute while disabled is a normal component property (with getter/setter). Component properties support dynamic data binding annotations such as @load/@init (which will call setters on the component) while the special attributes evaluate at zul parse time and determine whether a component is created in the first place, hence the limitation: No component -> no data binding. That's why you can only use static EL expressions on a special attribute ${...}. This explains your first observation.

What you didn't mention is how the variable intService is defined ... I can only speculate it might be a reference binding intService="@ref(...)" or something else not available when the static expression \${vm.reorder(intService)} evaluates.

If you are using ZK EE you can use the <if>-shadow element (in the zuti.jar), which supports MVVM data binding on the test property.

<if test="@load(vm.reorder(intService))"> <!-- or @init if only evaluated once -->
<button .../>
</if>


In order to give you a working solution for ZK CE I'd need to know what the intService variable actually is, ideally a simplified running example on zkfiddle where I can just make the necessary changes. And provide an updated link here.

Indeed, it is loaded using a @ref and in the end i did use shadow if, but still did not understood what happened. Thank you for this explanation - it is clear what happened there now

( 2021-08-24 13:21:36 +0800 )edit

you're welcome

( 2021-08-24 14:13:52 +0800 )edit
[hide preview]