(Quick Reference)

5 Selector - Reference Documentation

Authors: groovyquan

Version: 0.5.1

5 Selector

5.1 Selector overview

jQuery & CSS 3 style Server side selectors, that allows very powerful and robust queries.

The select method is injected to Component,which returns a list of Component.

View code

<z:window id="window" apply="MyComposer">
    <z:textbox name="t1" value="value1"/>
    <z:textbox id="t2" value="value2"/>
    <z:textbox value="value3"/>
</z:window>

Composer code

class MyComposer{

def afterCompose = {Component window -> assert 3 == window.select("textbox").size() // select method returns List<Component> assert "value2" == window.select("#t2")[0].value assert "value1" == window.select("textbox[name='t1']")[0].value }

}

5.2 Base Selector

// Matches any Button component
"button"

// Matches any Component with ID "btn" "#btn"

// Matches any Button with ID "btn" "button#btn"

// Matches any Button whose label is "Submit" "button[label='Submit']"

5.3 Selector combinations

// Matches any Button who has a Window ancestor
"window button"

// Matches any Button whose parent is a Window "window > button"

// Matches any Button whose previous sibling is a Window "window + button"

// Matches any Button who has a Window as a senior sibling "window ~ button"

// Matches any Button whose parent is a Div and grandparent is a Window "window > div > button"

5.4 Comparison with CSS3 Selector

SyntaxIn CSS 3 SelectorIn Component SelectorComment
tagnameDOM element typeComponent type 
#idDOM IDComponent ID 
.classCSS classSClass / ZClass 
attr='value'DOM attributegetAttr() or dynamic attributeIf getAttr() is not a method on such component, it is skipped
:pseudo-classPseudo classPseudo class:root, :empty, :first-child, :last-child, :only-child, :nth-child(), :nth-last-child()
::pseudo-elementPseudo elementN/A 
> + ~CombinatorCombinatorIdentical to CSS 3 combinators

5.5 More about Selector

You can also use Selector independently. For example:

Window win;

// returns a list of components, containing all labels in the page Selectors.find(page, "label");

// returns all components with id "myId" under the Window win. (including itself) Selectors.find(win, "#myId");

// returns all components whose .getLabel() value is "zk" (if applicable) Selectors.find(page, "[label='zk']");

// returns all captions whose parent is a window Selectors.find(win, "window > caption");

// returns all buttons and toolbarbuttons Selectors.find(page, "button, toolbarbutton");

// you can assemble the criteria: // returns all labels, whose parent is a window of id "win", and whose value is "zk" Selectors.find(page, "window#win > label[value='zk']");