Can I use an include inside an hbox in zk? [closed]

Matthias84
3 2

I have the following code in my zul:

<hbox>
<include src="firstInclude.zul" />
<include src="secondInclude.zul" />
</hbox>


I keep getting a page-not-found error for firstInclude.zul. The firstInclude.zul file is in the same directory as the file containing the code depicted above. The zul file containing the code above, on the other hand, is dynamically included into a modal window. The window's viewmodel is performing this task. What am I doing wrong?

delete retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted"by cor3000 close date 2019-10-21 18:38:57

Sort by » oldest newest most voted

cor3000
4887 2 7

Relative include paths are resolved based to the current desktop's path (which is the location of the main.zul currently displayed).

If you want to check this in code place a breakpoint in AbstractExecution:toAbsolutePath() and observe which uri is passed in and which currentDirectory is prepended.

(This process is independent of any components, so <hbox> has nothing to do with it. Also this is independent of dynamic usage.)

Assume this static structure:

/pages/main.zul
/pages/sub/sub.zul
/pages/sub/sub-include.zul


main.zul

<div>
<include src="sub/sub.zul"/>
</div>


sub/sub.zul

<div>
SUB
<div>
<include src="sub-include.zul"/>
</div>
</div>


Will result in this error:

org.zkoss.zk.ui.UiException: Page not found: /pages/sub-include.zul
at org.zkoss.zk.ui.http.ExecutionImpl.getPageDefinition(ExecutionImpl.java:385)
at org.zkoss.zul.Include.afterCompose(Include.java:509)
...


Changing the included src url like below will fix this issue.

<include src="sub/sub-include.zul"/>


I agree this is not obvious, but that's how it behaves.

A more robust alternative is to use absolute paths (starting with a /) to avoid relative path resolution issues.

<include src="/pages/sub/sub-include.zul"/>