私は静的コンテンツ専用のサーバーを持っていますので、javascriptファイルを格納するためにリソースディレクトリを使いたくないのですが、<h:outputScript />
タグの使用をやめたくありません。リモートファイルで<h:outputScript />を使用するにはどうすればよいですか?
RES_NOT_FOUNDの代わりに、そのタグがファイルが配置されている静的サーバーへのリンクを生成するようにすることはできますか。生成するには<h:outputScript name="#{requestBean.staticURL}/javascript.js"/>
を:私も
...ファイルがあるかどうかを確認するためにJSFを必要としない私が試した<script type="text/javascript" src="http://static.server.com/javascript.js"></script>
をしかし、それは生成:<script type="text/javascript" src="RES_NOT_FOUND"></script>
は、私が何を行うことができます?
解決策: ダニエルは素晴らしいソリューションを教えてくれました。
私はOmnifacesのソースコードをダウンロードしにorg.omnifaces.resourcehandler.CDNResourceHandle.createResource(String resourceName, String libraryName)
方法を変更した:私は私のweb.xmlに以下を追加することができ、この変更ファイル
<context-param>
<param-name>org.omnifaces.CDN_RESOURCE_HANDLER_URLS</param-name>
<param-value>
somelib2:%=http://cdn.example.com/somelib2,
js/script1.js=http://cdn.example.com/js/script1.js,
somelib:js/script2.js=http://cdn.example.com/somelib/js/script2.js,
otherlib:style.css=http://cdn.example.com/otherlib/style.css,
images/logo.png=http://cdn.example.com/logo.png
</param-value>
</context-param>
通知を
public Resource createResource(String resourceName, String libraryName) {
final Resource resource = wrapped.createResource(resourceName, libraryName);
if (cdnResources == null) {
return resource;
}
String resourceId = ((libraryName != null) ? libraryName + ":" : "") + resourceName;
String path = cdnResources.get(resourceId);
if(path == null){
if(libraryName != null){
resourceId = libraryName + ":%";
path = cdnResources.get(resourceId);
if(path == null){
return resource;
}
path += "/"+resourceName;
}
else return resource;
}
final String requestPath = path;
return new ResourceWrapper() {
@Override
public String getRequestPath() {
return requestPath;
}
@Override
public Resource getWrapped() {
return resource;
}
};
}
somelib2:%=http://cdn.example.com/somelib2
、somelib2ライブラリの任意のリソースを指す相対パスはhttp://cdn.example.com/somelib2、例えば:
<h:outputScript name="js/myjs.js" library="somelib2" />
意志出力:
<script type="text/javascript" src="http://cdn.example.com/somelib2/js/myjs.js"></script>
これは<h:outputScript /><h:outputStylesheet /><h:graphicImage />
、リソースを使用するもので動作します。
ありがとう、あなたの提案は私をたくさん助けたし、私の問題を解決:) 私はCDNResourceHandle.createResource(文字列resourceNameのを、変更String libraryName)メソッドを使用してライブラリを使用して、すべての単一ファイルをリストするのではなく、ライブラリを使用できるようにします。 –
変更に興味がある場合は、この部分を変更しました: 'String resourceId = (libraryName!= null)?libraryName + ":": "")+ resourceName; 文字列パス= cdnResources.get(resourceId); 場合(パス== NULL){ \t IF(LIBRARYNAME = NULL!){ \t \t RESOURCEID = LIBRARYNAME + "%"。 \t \tパス= cdnResources.get(resourceId); \t \t if(path == null){ \t \t \t return resource; \t \t} \t \t path + = "/" + resourceName; \t} \tその他のリソースを返します。 } 最終列requestPath =パス;これは仕事をする ' –
:' <コンテキストPARAM> org.omnifaces.CDN_RESOURCE_HANDLER_URLS alibraryname:%= HTTP://cdn.example.com < ' ' –