0

Slider curpos @init value is capped at 100.0 if maxpos is also set using @init and is greater than 100.0

asked 2024-01-26 17:27:39 +0800

Zantetsuken gravatar image Zantetsuken
1

updated 2024-01-30 16:20:17 +0800

hawk gravatar image hawk
3205 1 5
http://hawkphoenix.blogsp... ZK Team
<zk>
    <window apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('pkg$.VM')">
        <slider mode="decimal" step="0.001" minpos="0" maxpos="@init(vm.maxpos)" curpos="@bind(vm.curpos)" />
        <slider mode="decimal" step="0.001" minpos="0" maxpos="1000.0" curpos="@bind(vm.curpos)" />
    </window>
</zk>
import java.math.BigDecimal;

import org.zkoss.bind.annotation.Init;

public class VM {
    BigDecimal maxpos;
    BigDecimal curpos;

    @Init
    public void init() {
        maxpos = curpos = BigDecimal.TEN.multiply(BigDecimal.TEN).multiply(BigDecimal.TEN);
    }

    public BigDecimal getMaxpos() {
        return maxpos;
    }

    public void setMaxpos(BigDecimal maxpos) {
        this.maxpos = maxpos;
    }

    public BigDecimal getCurpos() {
        return curpos;
    }

    public void setCurpos(BigDecimal curpos) {
        this.curpos = curpos;
    }
}

The curpos property should be set to its intended value if maxpos allows it, the runtime shouldn't cap it at the maxpos default value.

https://zkfiddle.org/sample/2iuueog/5-MVVM-slider-curpos-maxpos-bug#source-2

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2024-01-30 16:24:06 +0800

hawk gravatar image hawk
3205 1 5
http://hawkphoenix.blogsp... ZK Team

Because zk sets curpos earlier than maxpos internally when using data binding. And if you set curpos with a value over maxpos, the slider enforces its curpos with maxpos. That's why you see the result is 100 because the default maxpos is 100.

workaround:

<slider mode="decimal"  step="0.001" minpos="0" maxpos="${vm.maxpos}" curpos="@bind(vm.curpos)" />

Because zk evaluates EL earlier than data binding.

link publish delete flag offensive 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

RSS

Stats

Asked: 2024-01-26 17:27:39 +0800

Seen: 3 times

Last updated: Jan 30

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