Search code examples
javaeventsmvvmzkzul

onFocus and onBlur attribute in zk?


Before I google :

http://www.zkoss.org/zkdemo/event/client-side_event_handling

But i dont undetstand clearly .

pls tell me:

What is the purpose of use onFocus and onBlur attribute in zk ?


Solution

  • In this context, "focus" refers to a form field being the field currently accepting user input.

    1) A field can have focus by default on initial render:

    <textbox focus="true"/>
    

    2) A field can be given focus by ZK:

    public void focusOnTextbox() {
        myTextbox.setFocus(true);
    }
    

    3) A field can gain focus when the user clicks on it, as shown in the demo you referenced.

    Inherent to the concept of focus, only one field can have focus at a time. Thus, when a second field gains focus, the first field loses focus; this is known as "blurring".

    1) A field can blur when another field gains focus.

    2) A field can blur when the user clicks outside the field, at this point no fields have focus.

    3) A field can blur when it's focus is removed by ZK:

    public void focusOffTextbox() {
        myTextbox.setFocus(false);
    }