Search code examples
widgetzk

Seaching widgets in zk


Is it possible to find all widgets that have id begining from string in zk ? jquery example:

 $( "input[id^='news']" ).val( "news here!" );

In zk maybe something like this:

 zk.Widget.$([id^='news']);

Solution

  • If you are trying to find widget id (Widget and not Component) you can use :

    zk.Widget.$(jq("input[id^='news']"));
    

    In fact "jq" is equivalent of "$" in ZK.

    ZK Client Engine is based on jQuery. It inherits all functionality provided by jQuery

    http://www.zkoss.org/javadoc/latest/jsdoc/global/jq.html

    Warning :

    ZK use 2 terms for widget/component :

    • Component for Server Side (java and zul)
    • Widget for Client Side (DOM and js)

    ZK generate unique id for widgets, that's why you could not find component ID (zul or java id), with standard jquery selector (with $ or jq).

    If you need to find a widget with it's component id use :

    jq("$componentid");
    

    I am pretty sure, it's impossible to write a selector for matching the begining of components id.

    Change your code (if possible) to use Component SCLASS attribute (class attribute for DOM element) it should be way more simple !

    Her an example for selection of all "Button" component with sclass "findme" :

    zk.Widget.$(jq("@button.findme"));