SunnyPenguin
SunnyPenguin

Reputation: 157

How to inject or import libraries in the tapestry core stack to a component?

I'm using tapestry 5.4.1. I have a component with a module that requires prototype. I know prototype is available in the core stack. However how do I import this as a dependency.

My module:

define(["prototype"], function(container, link) {
  return new Ajax.PeriodicalUpdater(container, link, {
      method : 'post', frequency : 5, decay : 1
  });
});

I tried adding this to the class but the path cannot be resolved

@Import(library = {"prototype.js"})
public class Update {

Tried injecting the asset and adding it to the environmental javascriptsupport but it somehow looks for it in the wrong location.

@Inject
@Path("classpath:META-INF/assets/tapestry5/prototype.js")
private Asset prototype;

and

javascriptSupport.importJavaScriptLibrary(prototype);
javascriptSupport.require("update").with(container, getLink());

I don't want to hard code the url with the generated hash.

/assets/meta/z67bxxxx/tapestry5/scriptaculous_1_9_0/prototype.js

Anything I am missing here? Any help would be appreciated.

Upvotes: 0

Views: 546

Answers (1)

xl0e
xl0e

Reputation: 371

Make sure you define correct infrastructure in your AppModule

@ApplicationDefaults
public static void contributeApplicationDefaults(MappedConfiguration<String, Object> configuration) {

    configuration.add(SymbolConstants.JAVASCRIPT_INFRASTRUCTURE_PROVIDER, "prototype");
}

You don't have to specify dependency clearly ["prototype"].

Upvotes: 1

Related Questions