int box and constraint="no negative"

asked 2019-09-27 20:04:08 +0800

bibabobaofzimbabwe gravatar image bibabobaofzimbabwe
3 1

updated 2019-10-01 12:36:49 +0800

cor3000 gravatar image cor3000
5384 2 7
ZK Team

Validation of in box not work correctly

1)After I put minus sign "-" and press "Tab" Message box with

For input string: "-"

appear With stacktrace

14:51:01.728 [http-bio-8080-exec-10] ERROR org.zkoss.zk.ui.impl.UiEngineImpl - java.lang.NumberFormatException: For input string: "-" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:572) at java.lang.Integer.<init>(Integer.java:867) at org.zkoss.lang.Classes.coerce(Classes.java:1325) at org.zkoss.bind.impl.ParamCall$2.resolveParameter(ParamCall.java:132) at org.zkoss.bind.impl.ParamCall$2.resolveParameter(ParamCall.java:105) at org.zkoss.bind.impl.ParamCall.resolveParameter(ParamCall.java:179) at org.zkoss.bind.impl.ParamCall.call(ParamCall.java:145) at org.zkoss.bind.impl.BinderImpl.handleNotifyChange(BinderImpl.java:1883) at org.zkoss.bind.impl.BinderImpl.doExecute(BinderImpl.java:2051)

I expect to see clean log (user mistake !) with internationalized message

Zul Code

 <window viewModel="@id('vm1') @init('TestVM')">
     <intbox constraint="no negative"

ViewModel class

 public class TestVM {
     public void doTest(@BindingParam("on") int value){
         System.out.println("value = " + value);

On big form validation messages not appear at all if put negative value and press tab key quickly.

How to fix this in our application?

delete flag offensive retag edit

2 Answers

Sort by » oldest newest most voted

answered 2019-10-01 12:14:16 +0800

cor3000 gravatar image cor3000
5384 2 7
ZK Team

updated 2019-10-01 18:04:09 +0800

Hi bibaboba,

the onChanging event will sent the typed user input before validation or conversion. It will contain the raw string the user was currently typing, it will send whenever the user makes a small pause between keystrokes. In your case this value can't be converted to an int matching your method signature.

For onChanging use String instead:

public void doTest(@BindingParam("on") String value){
    System.out.println("value = " + value);    

If you want to listen to the converted and validated results, please use the onChange event. And if you need intermediate results (while typing) use <intbox instant="true" ...>, which will send an onChange event when the user pauses typing.

link publish delete flag offensive edit

answered 2019-10-02 18:09:25 +0800

bibabobaofzimbabwe gravatar image bibabobaofzimbabwe
3 1

Thank you, cor3000! Your solution worked perfectly.

link publish delete flag offensive edit


you're welcome

cor3000 ( 2019-10-02 18:35:55 +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




Asked: 2019-09-27 20:04:08 +0800

Seen: 14 times

Last updated: Oct 02 '19

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