get size of include

asked 2022-10-14 15:35:09 +0800

nome gravatar image nome
7 2

updated 2022-10-14 15:39:05 +0800

Hi guys, I am new in ZK and need your help. I want to get width and height of include. how to achieve it?


<include src="~./zul/dashboard/request.zul" hflex="1" vflex="1"/>


delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2022-10-14 18:30:23 +0800

MDuchemin gravatar image MDuchemin
2298 1 5
ZK Team

your include has the vlfex and hflex attributes, which means that it will size up to the available parent's size.

Regarding finding out what it will calculate up to will require a few steps, since ZK doesn't usually keep track of client-side sizes. There are a number of reasons for that. First, that would require keeping track of a lot of different components sizes. Second, these sizes can change pretty much anytime. This said, you can set the onAfterSize event to tell the component to retrieve its size and send it back to the server.

You can use the onAfterSize event to receive an event anytime the component is resized (including when it is created initially) https://zkfiddle.org/sample/1sj1h1b/4-size-request-composer sample asking for width, but you can get other data from the event as well.

See the afterSize event for details on that: https://www.zkoss.org/javadoc/latest/zk/org/zkoss/zk/ui/event/AfterSizeEvent.html

Alternatively, you can execute arbitrary JavaScript targeting a component of your choice if the info you need is not available in the onAfterSize event, such as retrieving the full client rects. I've put a sample below, but that's just to illustrate the order of operations, and not what I would actually recommend doing: https://zkfiddle.org/sample/1sj1h1b/3-size-request-composer (declare an arbitrary script, use Clients.evalJavaScript to trigger it, send a custom event back, and lastly listen to the custom event).

link publish delete flag offensive edit


I will point out that you should consider whether you actually need to retrieve the size of a component. In general it's easier to give components dynamic sizings.. Retrieving client value can also be unreliable due to zoom, scaling, pixel ratio, etc. which the browser may not tell you about.

MDuchemin ( 2022-10-14 18:32:45 +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

1 follower



Asked: 2022-10-14 15:35:09 +0800

Seen: 5 times

Last updated: Oct 14

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