1

How to get components by their css class ?

asked 2017-05-30 05:03:17 +0800

Bhushanngage gravatar image Bhushanngage
59 6

updated 2017-05-30 05:06:32 +0800

Lets say, I am appending Labels to same Div in loop. I am setting css class to each Label.

Now how can I get list of Labels by their css class (like we do getElementsByClassName() in JS)?

delete flag offensive retag edit

Comments

mvvm or mvc? for MVVM : http://books.zkoss.org/zk-mvvm-book/8.0/syntax/selectorparam.html

chillworld ( 2017-05-30 10:34:22 +0800 )edit

MVC, we are using SelectorComposer listener. Also, these component are not present in my zul file, I am creating them in Java class(Listener)

Bhushanngage ( 2017-05-30 11:12:02 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-05-31 05:25:09 +0800

chillworld gravatar image chillworld flag of Belgium
5322 4 9
https://github.com/chillw...

updated 2017-05-31 05:25:38 +0800

Your answer is actually in the link that I provided.

You can use the class selectors.

You can use this method : find(Component root, java.lang.String selector)

These are the selectors :

  • find(root,"#componentId")
  • find(root,"tagName")
  • find(root,".className")
  • find(root,":root")
  • find(root,"button[label='Submit']")
  • find(root,"window > button")

Chill.

link publish delete flag offensive edit

Comments

This is exactly I want. Thanks.

Bhushanngage ( 2017-05-31 06:53:27 +0800 )edit

A shortcut using the same internally is Component.query queryAll or Desktop.query /queryAll (e.g. https://www.zkoss.org/javadoc/latest/zk/org/zkoss/zk/ui/Component.html#queryAll(java.lang.String))

cor3000 ( 2017-06-06 05:54:59 +0800 )edit

Component.queryAll() vs Desktop.query() Whose performance is better ?

Bhushanngage ( 2017-06-07 05:08:55 +0800 )edit

both use the same search algorithm, so it's basically the same. Searching from a Component directly will only search the sub-tree of that component. So if you already know where to search you'll be quicker starting from a specific component instead of searching the whole Desktop.

cor3000 ( 2017-06-12 02:14:41 +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

Follow
2 followers

RSS

Stats

Asked: 2017-05-30 05:03:17 +0800

Seen: 45 times

Last updated: May 31 '17

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