Include javascript with resources via h:outputScript

后端 未结 4 795
伪装坚强ぢ
伪装坚强ぢ 2021-02-10 22:16

I would like to include JScolor to my jsf application. It is possible via

4条回答
  •  一整个雨季
    2021-02-10 23:04

    The JS file is apparently referencing picture files via a relative path which do not represent a valid JSF resource URL.

    The generates a JSF resource URL which goes through the JSF resource handler which worries about among others automatic localization and versioning. It would generate an URL prefixed with /javax.faces.resource and also append the currently used FacesServlet URL mapping such as *.xhtml or /faces/*.

    Thus, if you mapped the faces servlet on *.xhtml and have a /resources/jscolor folder with the JS and image files and have referenced the JS file as follows,

    
    

    then it would generate

    
    

    However, the image files are not physically available in /javax.faces.resource/jscolor folder, instead they are physically available in /resources/jscolor folder. The /javax.faces.resource would only be automatically resolved when you apply the faces servlet mapping on the resource name. Thus, this specific case would only work if you manually edit the jscolor.js file to change image file names from e.g. arrow.gif to arrow.gif.xhtml.

    If you don't utilize any automatic localization or versioning features of the JSF resource resolver, nor are using any special custom resource resolvers which requires real JSF resources rather than static HTML elements, such as this one, then you can also just go ahead with a plain vanilla HTML

提交回复
热议问题