0

Load package descriptor from imported module

asked 2021-01-15 23:36:04 +0800

aUser gravatar image aUser
137 1 4

updated 2021-01-15 23:36:31 +0800

Hello,

i have a webapp called test that imports a module called utilityModule using pom.xml like this:

<dependency>
     <groupId>groupId</groupId>
     <artifactId>utilityModule</artifactId>
     <version>1.0.0</version>
</dependency>

Inside this utilityModule i have a package descriptor at this location:

src/main/resources/web/dir1/dir2/js/utilityPackage/utilityPackage.wpd

and a .zul page at this location:

src/main/resources/web/dir1/dir2/main.zul

Inside the main.zul page from the utilityModule i'm calling a script and i need to import this utilityPackage but i can't easily reference it..

I can't use this because it tries to reference the file from the test webapp

<script>
    zk.load('utilityPackage'){  // doesn't work
        ....
    }
</script>

and i can't reference it neither this way as suggested here

<script>
    zk.load("${c:encodeURL('~.utilityPackage/utilityPackage')}"){   // doesn't work
        ....
    }
</script>

Any help on how to reference the utilityPackage from main.zul?

Thank you

delete flag offensive retag edit

4 Answers

Sort by ยป oldest newest most voted
1

answered 2021-01-19 10:33:05 +0800

cor3000 gravatar image cor3000
6280 2 7

updated 2021-01-19 10:47:52 +0800

ok good to know the mechanism works using

/web/js/[yourpackage]/zk.wpd

That's let's say level 1. And can be loaded using zk.load('yourpackage', callback). Since ZK uses this mechanism internally also for nested modules this functionality is also available to you. Still the path in your source files needs to start with /web/js followed by your package folders, then zk.wpd

e.g.:

/web/js/dir1/dir2/somepackage/zk.wpd

<package name="dir1.dir2.somepackage" language="xul/html">
    <!-- your scripts, widgets -->
</package>

you'll then be able to load this package via zk.load('dir1.dir2.somepackage', callback).

If you provide multiple file with the same folder/names it depends on the java classloader which resource is found first and loaded. You have to avoid this if you want reliable/predictable wdp loading.

And the docs: https://www.zkoss.org/wiki/ZKClient-sideReference/WidgetPackageDescriptor

link publish delete flag offensive edit
1

answered 2021-01-18 10:13:59 +0800

cor3000 gravatar image cor3000
6280 2 7

updated 2021-01-18 10:17:48 +0800

I can't use this because it tries to reference the file from the test webapp

It is expected that all module resources are loaded via the webapp that includes them. The code you tried can't work for several reasons:

<script>
    zk.load('utilityPackage'){  // doesn't work
        ....
    }
</script>

Correct observation it doesn't work for several reason:

1) it's syntactically wrong, it's not even correct javascript

2) it is not following the API docs on zk.load - the zk.load function has 2 arguments, a package name and callback function to be called when the package is loaded.

Correct syntax and api usage:

<script>
    zk.load('utilityPackage', function() {
        ...
    });
</script>

This will then load the package 'utilityPackage' using the following url inside your test webapp ...

http(s)://[yourserver]/test/zkau/web/[someid]/js/utilityPackage.wpd

... which will then try to find the corresponding zk.wpd file in your classpath under (also in your utilityModule.jar):

web/js/utility/zk.wpd

The related source location in your module project is:

src/main/resources/web/js/utility/zk.wpd

3) you placed your file into unexpected subfolders (dir1/dir2) and the wrong file name utilityPackage.wpd instead of zk.wpd (we had all this covered in a your previous question ... no need to change this pattern).

src/main/resources/web/dir1/dir2/js/utilityPackage/utilityPackage.wpd

To start with you have to place it below:

src/main/resources/web/js/utilityPackage/zk.wpd

Important are the first two folders web/js ... and the name zk.wpd.

(Again can only remind you that we offer dedicated support to help more efficiently to avoid these kind of confusion from the start.)

link publish delete flag offensive edit
0

answered 2021-01-18 19:35:47 +0800

aUser gravatar image aUser
137 1 4

I need to apologize for this question, i made several mistakes writing it even though the code i'm using respects the correct syntax for the package loading and zk.wpd filename.

I tried to put my folder with the needed files under

src/main/resources/web/js/utilityPackage/zk.wpd

in the imported module and it worked. That was just about it, putting the folder on that path. But is it always necessary? I mean can't i reference a file that has a path in my module as

src/main/resources/web/dir1/dir2/js/utilityPackage/zk.wpd

?

I didn't find the documentation for this structured way to organize files inside a webapp on zk documentation, can i read it somewhere?

If i have the correct path for both my webapp and a module i import, say for example again this path

src/main/resources/web/js/utilityPackage/zk.wpd

Will this file be red from the webapp or the module?

Thank you

link publish delete flag offensive edit
0

answered 2021-01-19 16:43:35 +0800

aUser gravatar image aUser
137 1 4

Ok, it's very clear, however in the docs you linked i could only see a reference to the path web/js/..., quoting:

WPD must be named zk.wpd and placed in the same directory as the widget classes. For example we would place it under web/js/com/foo.

I'm wondering if the path web/js/ is related to ZK's standard or maybe Maven related? If it is ZK's related, are there other "standard" paths that i should follow in order to load other kind of files correctly?

Thanks

link publish delete flag offensive edit

Comments

yes that's a ZK convention, ZK's classpath resources go below /web and ZK's js packages below /web/js maybe there are others right now I don't recall which ...

this is the java implementation class https://www.zkoss.org/javadoc/latest/zk/org/zkoss/web/util/resource/ClassWebResource.html

cor3000 ( 2021-01-19 18:34:43 +0800 )edit

here a related config option mentioning this internal mechanism https://www.zkoss.org/wiki/ZKConfigurationReference/zk.xml/TheLibraryProperties/org.zkoss.web.util.resource.dir (don't use it, it's much more flexible work inside src/main/resources/web)

cor3000 ( 2021-01-19 18:43:20 +0800 )edit

Thank you, gonna read some docs, i'll keep using src/main/resources/web as you suggest since i don't think i need to use that org.zkoss.web.util.resource.dir yet

aUser ( 2021-01-19 21:32:41 +0800 )edit

yes since you can only specify one value for org.zkoss.web.util.resource.dir I'd keep it available in case you need to apply some kind of hot patch in an emergency

cor3000 ( 2021-01-20 09:23:32 +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
1 follower

RSS

Stats

Asked: 2021-01-15 23:36:04 +0800

Seen: 12 times

Last updated: Jan 19 '21

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