Javacsript module problem

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Javacsript module problem

Ric-01
Dear all,

 From a java class I load a js module and try to invoke a method in it
using the following line:

javaScriptSupport.require("hotel/loadingIndicatorTrigger").invoke("showLoadingIndicator");

The script file loadingIndicatorTrigger.js is in
src/main/resources/META-INF/modules/hotel/loadingIndicatorTrigger.js

This is the content of the script:
requirejs.config({
"shim": {
"hotel/globals/jquery.loading.indicator": {
deps: ["jquery"]
}
}
});

define(["hotel/globals/jquery.loading.indicator"], function() {

function showLoadingIndicator() {
var homeLoader = jQuery('body').loadingIndicator({
useImage: false,
}).data("loadingIndicator");
homeLoader.show();
}

});

Now the browser console prompts always the following error: "RequireJS
error: require: moduleLib is undefined".

In my Eclipse I see a warning in above line of java code: "Couldn’t
resolve classpath asset from path
META-INF\modules\hotel\loadingIndicatorTrigger.js"

I tried different things like
define(["jquery", "hotel/globals/jquery.loading.indicator"], function($) {
buterror is always the same.

Is there something missing in my configuration or in the applications
module class?

Thanks for your help!


Regards, Erich





---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Javacsript module problem

Cezary Biernacki
Hi Erich,

One problem I can see is that function showLoadingIndicator() is not
exported from define(.., function() { ... }). You should add "return {
showLoadingIndicator: showLoadingIndicator };" at the end of "function() {
... }".

However I believe it will not solve a problem indicated by message
"Couldn’t resolve classpath asset from path
META-INF\modules\hotel\loadingIndicatorTrigger.js" (I guess you are on
Windows, so slashes are translated to slashes, but it should not be an
issue). It suggests that the JS file is missing. So either it was not
copied from the source directories to the directories (or JARs) used during
execution - check your build directories to see if the file is really
there, if not, than run your build process. Or file name
"hotel/loadingIndicatorTrigger"
is misspelled in somewhere.

Cezary





On Sun, Mar 25, 2018 at 3:19 PM, Erich Gormann <[hidden email]> wrote:

> Dear all,
>
> From a java class I load a js module and try to invoke a method in it
> using the following line:
>
> javaScriptSupport.require("hotel/loadingIndicatorTrigger").
> invoke("showLoadingIndicator");
>
> The script file loadingIndicatorTrigger.js is in
> src/main/resources/META-INF/modules/hotel/loadingIndicatorTrigger.js
>
> This is the content of the script:
> requirejs.config({
> "shim": {
> "hotel/globals/jquery.loading.indicator": {
> deps: ["jquery"]
> }
> }
> });
>
> define(["hotel/globals/jquery.loading.indicator"], function() {
>
> function showLoadingIndicator() {
> var homeLoader = jQuery('body').loadingIndicator({
> useImage: false,
> }).data("loadingIndicator");
> homeLoader.show();
> }
>
> });
>
> Now the browser console prompts always the following error: "RequireJS
> error: require: moduleLib is undefined".
>
> In my Eclipse I see a warning in above line of java code: "Couldn’t
> resolve classpath asset from path META-INF\modules\hotel\loading
> IndicatorTrigger.js"
>
> I tried different things like
> define(["jquery", "hotel/globals/jquery.loading.indicator"], function($) {
> buterror is always the same.
>
> Is there something missing in my configuration or in the applications
> module class?
>
> Thanks for your help!
>
>
> Regards, Erich
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Javacsript module problem

Ric-01
Hi Cezary,

first thanks. Yes, it was a mixture of all that, meanwhile I studied the
requirejs documentation strongly and checked out the tapestry5-jquery
project, to learn from it.

And now a lot of things are already working!

A lot in requirejs and AMD semms to be magical and I prefer to do java
coding, but we'll never stop to learn...

Regards, Erich



Am 26.03.2018 17:21, schrieb Cezary Biernacki:

> Hi Erich,
>
> One problem I can see is that function showLoadingIndicator() is not
> exported from define(.., function() { ... }). You should add "return {
> showLoadingIndicator: showLoadingIndicator };" at the end of "function() {
> ... }".
>
> However I believe it will not solve a problem indicated by message
> "Couldn’t resolve classpath asset from path
> META-INF\modules\hotel\loadingIndicatorTrigger.js" (I guess you are on
> Windows, so slashes are translated to slashes, but it should not be an
> issue). It suggests that the JS file is missing. So either it was not
> copied from the source directories to the directories (or JARs) used during
> execution - check your build directories to see if the file is really
> there, if not, than run your build process. Or file name
> "hotel/loadingIndicatorTrigger"
> is misspelled in somewhere.
>
> Cezary
>
>
>
>
>
> On Sun, Mar 25, 2018 at 3:19 PM, Erich Gormann<[hidden email]>  wrote:
>
>> Dear all,
>>
>>  From a java class I load a js module and try to invoke a method in it
>> using the following line:
>>
>> javaScriptSupport.require("hotel/loadingIndicatorTrigger").
>> invoke("showLoadingIndicator");
>>
>> The script file loadingIndicatorTrigger.js is in
>> src/main/resources/META-INF/modules/hotel/loadingIndicatorTrigger.js
>>
>> This is the content of the script:
>> requirejs.config({
>> "shim": {
>> "hotel/globals/jquery.loading.indicator": {
>> deps: ["jquery"]
>> }
>> }
>> });
>>
>> define(["hotel/globals/jquery.loading.indicator"], function() {
>>
>> function showLoadingIndicator() {
>> var homeLoader = jQuery('body').loadingIndicator({
>> useImage: false,
>> }).data("loadingIndicator");
>> homeLoader.show();
>> }
>>
>> });
>>
>> Now the browser console prompts always the following error: "RequireJS
>> error: require: moduleLib is undefined".
>>
>> In my Eclipse I see a warning in above line of java code: "Couldn’t
>> resolve classpath asset from path META-INF\modules\hotel\loading
>> IndicatorTrigger.js"
>>
>> I tried different things like
>> define(["jquery", "hotel/globals/jquery.loading.indicator"], function($) {
>> buterror is always the same.
>>
>> Is there something missing in my configuration or in the applications
>> module class?
>>
>> Thanks for your help!
>>
>>
>> Regards, Erich
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: Javacsript module problem

Svein
Take a look at the page source in the browser. Tapestry 5.4 loads modules at the end of the page.

A sample of the tapestry way (what I know) to load shim:
In AppModule.java
@Contribute(ModuleManager.class)
public static void setupMyBaseModules(MappedConfiguration<String, Object> configuration,
                                      @Path("META-INF/assets/jacillacore/highcharts/highcharts.src.js") Resource highchartsSrc,
                                      @Path("META-INF/assets/jacillacore/highcharts/highcharts-more.src.js") Resource highchartsMoreSrc) {
    configuration.add("highcharts", new JavaScriptModuleConfiguration(highchartsSrc));
    configuration.add("highchartsMore", new JavaScriptModuleConfiguration(highchartsMoreSrc).dependsOn("highcharts"));
}

I would recommend to use AMD modules instead of inline javascript.

S-E

From: Ric-01 [via Apache Tapestry Mailing List Archives] <[hidden email]>
Sent: mandag 26. mars 2018 23:07
To: Svein-Erik Løken <[hidden email]>
Subject: Re: Javacsript module problem

Hi Cezary,

first thanks. Yes, it was a mixture of all that, meanwhile I studied the
requirejs documentation strongly and checked out the tapestry5-jquery
project, to learn from it.

And now a lot of things are already working!

A lot in requirejs and AMD semms to be magical and I prefer to do java
coding, but we'll never stop to learn...

Regards, Erich



Am 26.03.2018 17:21, schrieb Cezary Biernacki:

> Hi Erich,
>
> One problem I can see is that function showLoadingIndicator() is not
> exported from define(.., function() { ... }). You should add "return {
> showLoadingIndicator: showLoadingIndicator };" at the end of "function() {
> ... }".
>
> However I believe it will not solve a problem indicated by message
> "Couldn’t resolve classpath asset from path
> META-INF\modules\hotel\loadingIndicatorTrigger.js" (I guess you are on
> Windows, so slashes are translated to slashes, but it should not be an
> issue). It suggests that the JS file is missing. So either it was not
> copied from the source directories to the directories (or JARs) used during
> execution - check your build directories to see if the file is really
> there, if not, than run your build process. Or file name
> "hotel/loadingIndicatorTrigger"
> is misspelled in somewhere.
>
> Cezary
>
>
>
>
>
> On Sun, Mar 25, 2018 at 3:19 PM, Erich Gormann<[hidden email]</user/SendEmail.jtp?type=node&node=5733873&i=0>>  wrote:
>
>> Dear all,
>>
>>  From a java class I load a js module and try to invoke a method in it
>> using the following line:
>>
>> javaScriptSupport.require("hotel/loadingIndicatorTrigger").
>> invoke("showLoadingIndicator");
>>
>> The script file loadingIndicatorTrigger.js is in
>> src/main/resources/META-INF/modules/hotel/loadingIndicatorTrigger.js
>>
>> This is the content of the script:
>> requirejs.config({
>> "shim": {
>> "hotel/globals/jquery.loading.indicator": {
>> deps: ["jquery"]
>> }
>> }
>> });
>>
>> define(["hotel/globals/jquery.loading.indicator"], function() {
>>
>> function showLoadingIndicator() {
>> var homeLoader = jQuery('body').loadingIndicator({
>> useImage: false,
>> }).data("loadingIndicator");
>> homeLoader.show();
>> }
>>
>> });
>>
>> Now the browser console prompts always the following error: "RequireJS
>> error: require: moduleLib is undefined".
>>
>> In my Eclipse I see a warning in above line of java code: "Couldn’t
>> resolve classpath asset from path META-INF\modules\hotel\loading
>> IndicatorTrigger.js"
>>
>> I tried different things like
>> define(["jquery", "hotel/globals/jquery.loading.indicator"], function($) {
>> buterror is always the same.
>>
>> Is there something missing in my configuration or in the applications
>> module class?
>>
>> Thanks for your help!
>>
>>
>> Regards, Erich
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]</user/SendEmail.jtp?type=node&node=5733873&i=1>
>> For additional commands, e-mail: [hidden email]</user/SendEmail.jtp?type=node&node=5733873&i=2>
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]</user/SendEmail.jtp?type=node&node=5733873&i=3>
For additional commands, e-mail: [hidden email]</user/SendEmail.jtp?type=node&node=5733873&i=4>


________________________________
If you reply to this email, your message will be added to the discussion below:
http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/Javacsript-module-problem-tp5733870p5733873.html
To unsubscribe from [hidden email]<mailto:[hidden email]> Mailing List Archives, click here<
NAML<
http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
Reply | Threaded
Open this post in threaded view
|

Re: Javacsript module problem

Cezary Biernacki
In reply to this post by Ric-01
requirejs/AMD is much improvement of other "plain" Javascript approach once
you get sizeable amount of Javascript code, both developers (dependencies
between modules are explicit, and private parts can stay private instead of
polluting global space name), and for users (HTML can be rendered before
all Javascript is loaded and parsed). So I recommend understanding it - it
is not really much complicated. However one pain point for me is that if
some module fails to load for any reason, usually whole page becomes
unusable, especially in Tapestry which add modal "loader" layer.
Unfortunately a module can fail to load because of time out, and default
RequireJS is too small, like 7 seconds only. Tapestry in development mode
changes this value to 5 minutes, but uses default in the production mode,
so it might be hard to detect for developers. I fix this by increasing
"waitSeconds" parameter for RequireJS in my Layout component, e.g.:

    @SetupRender
    public void configureWaitSeconds() {
        // See http://requirejs.org/docs/api.html#config-waitSeconds
        javaScriptSupport.addModuleConfigurationCallback((config) ->
config.put("waitSeconds", 120));
    }


On Mon, Mar 26, 2018 at 11:06 PM, Erich Gormann <[hidden email]>
wrote:

> Hi Cezary,
>
> first thanks. Yes, it was a mixture of all that, meanwhile I studied the
> requirejs documentation strongly and checked out the tapestry5-jquery
> project, to learn from it.
>
> And now a lot of things are already working!
>
> A lot in requirejs and AMD semms to be magical and I prefer to do java
> coding, but we'll never stop to learn...
>
> Regards, Erich
>
>
>
>
> Am 26.03.2018 17:21, schrieb Cezary Biernacki:
>
>> Hi Erich,
>>
>> One problem I can see is that function showLoadingIndicator() is not
>> exported from define(.., function() { ... }). You should add "return {
>> showLoadingIndicator: showLoadingIndicator };" at the end of "function() {
>> ... }".
>>
>> However I believe it will not solve a problem indicated by message
>> "Couldn’t resolve classpath asset from path
>> META-INF\modules\hotel\loadingIndicatorTrigger.js" (I guess you are on
>> Windows, so slashes are translated to slashes, but it should not be an
>> issue). It suggests that the JS file is missing. So either it was not
>> copied from the source directories to the directories (or JARs) used
>> during
>> execution - check your build directories to see if the file is really
>> there, if not, than run your build process. Or file name
>> "hotel/loadingIndicatorTrigger"
>> is misspelled in somewhere.
>>
>> Cezary
>>
>>
>>
>>
>>
>> On Sun, Mar 25, 2018 at 3:19 PM, Erich Gormann<[hidden email]>
>> wrote:
>>
>> Dear all,
>>>
>>>  From a java class I load a js module and try to invoke a method in it
>>> using the following line:
>>>
>>> javaScriptSupport.require("hotel/loadingIndicatorTrigger").
>>> invoke("showLoadingIndicator");
>>>
>>> The script file loadingIndicatorTrigger.js is in
>>> src/main/resources/META-INF/modules/hotel/loadingIndicatorTrigger.js
>>>
>>> This is the content of the script:
>>> requirejs.config({
>>> "shim": {
>>> "hotel/globals/jquery.loading.indicator": {
>>> deps: ["jquery"]
>>> }
>>> }
>>> });
>>>
>>> define(["hotel/globals/jquery.loading.indicator"], function() {
>>>
>>> function showLoadingIndicator() {
>>> var homeLoader = jQuery('body').loadingIndicator({
>>> useImage: false,
>>> }).data("loadingIndicator");
>>> homeLoader.show();
>>> }
>>>
>>> });
>>>
>>> Now the browser console prompts always the following error: "RequireJS
>>> error: require: moduleLib is undefined".
>>>
>>> In my Eclipse I see a warning in above line of java code: "Couldn’t
>>> resolve classpath asset from path META-INF\modules\hotel\loading
>>> IndicatorTrigger.js"
>>>
>>> I tried different things like
>>> define(["jquery", "hotel/globals/jquery.loading.indicator"],
>>> function($) {
>>> buterror is always the same.
>>>
>>> Is there something missing in my configuration or in the applications
>>> module class?
>>>
>>> Thanks for your help!
>>>
>>>
>>> Regards, Erich
>>>
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>>
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Javacsript module problem

Thiago H de Paula Figueiredo
On Mon, Mar 26, 2018 at 6:45 PM, Cezary Biernacki <[hidden email]>
wrote:

>     @SetupRender
>     public void configureWaitSeconds() {
>         // See http://requirejs.org/docs/api.html#config-waitSeconds
>         javaScriptSupport.addModuleConfigurationCallback((config) ->
> config.put("waitSeconds", 120));
>     }
>

This is also the recommended way of changing the Require.js configuration.
Otherwise, you run the risk of dropping the Tapestry-added ones.

Thanks for the example, Cezary!

--
Thiago