0

I implement a custom JSF component with a JS and CSS file, and provide this component in a JAR, is it possible to inject the CSS and JS file or reference into the html that use my component by this component itself? And the Jar structure is like

- src
  aComponent.java
-resources
 -js
  acomponent.js
-css
  acompponent.css

I try to implement in encodeBegin() and encodeEnd() in acomponent.java like

public void encodeBegin(FacesContext context) {
        VirtualResource.addJsResource(context,  getClass().getPackage().getName().replace('.', '/') +   "/js/acomponent.js");
    }

But it does not work, does anyone knows how I can do this?

When any one use my jar and the acomponent in his html, it will load the CSS and JS by the component itself

Devssssss
  • 63
  • 1
  • 9
  • "But it does work", really? :) – BalusC Apr 03 '20 at 10:23
  • @BalusC Yes, I add it into encodeBegin, and it does not work, I just follow the pattern of exsit component,(although the other component put the method in encodeBefore, but my encodeBefore is never called)I do not know why, and ResourceDependency of javax.faces.application.ResourceDependency is not used in my project, is any other solution? – Devssssss Apr 03 '20 at 11:49
  • You said "But it does work". You didn't say "But it does not work". ResourceDepencency was introduced in JSF 2.0 more than a decade ago. Perhaps it's time to upgrade. – BalusC Apr 03 '20 at 12:10
  • Oh sorry, I missed the 'not' – Devssssss Apr 03 '20 at 12:57

0 Answers0