0

Issue with If validation

asked 2021-08-24 02:15:30 +0800

MartVq gravatar image MartVq
35 2

updated 2021-08-24 11:58:56 +0800

cor3000 gravatar image cor3000
6094 2 7
ZK Team

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)}" 
      disabled="@load(vm.isDisableOrder(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 flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-08-24 12:19:36 +0800

cor3000 gravatar image cor3000
6094 2 7
ZK Team

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.

link publish delete flag offensive edit

Comments

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

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

you're welcome

cor3000 ( 2021-08-24 14:13:52 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2021-08-24 02:15:30 +0800

Seen: 7 times

Last updated: Aug 24

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More