我正在尝试复制书中的一个例子,
该结构可以从下面附加的图像中可视化 -
更新
将使用该库的视图非常简单,如下所示 -
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title></title>
<h:outputStylesheet library="#{facesContext.viewRoot.locale}/default" name="css/rafa.css"/>
<h:outputScript library="#{facesContext.viewRoot.locale}/default" name="rafa.js"/>
</h:head>
<h:body>
<f:view locale="#{localeBean.mylocale}">
<div style="width:100%; text-align:center">
<h:form>
<h:commandButton value="Rafa at Roland Garros" action="#{localeBean.changeLocale('fr')}"/>
<h:commandButton value="Rafa at Wimbledon" action="#{localeBean.changeLocale('en')}"/>
<h:commandButton value="Rafa at US Open" action="#{localeBean.changeLocale('us')}"/>
<h:commandButton value="Rafa at Australian Open" action="#{localeBean.changeLocale('au')}"/>
</h:form>
</div>
<div style="width:100%; text-align:center">
<!--<h:graphicImage library="#{facesContext.viewRoot.locale}/default" name="img/rafa.png"/> -->
<h:graphicImage value="#{resource[facesContext.viewRoot.locale+='/default:img/rafa.png']}"/>
</div>
</f:view>
</h:body>
</html>
与
@Named
@RequestScoped
public class LocaleBean {
private String mylocale = "fr";
// getters & setters
}
我在内部使用Glassfish 4.1.1 Application Server
,Mojarra 2.2.12
是rendered HTML
-
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="j_idt2">
<title></title>
<script type="text/javascript" src="/glassfish-ee/javax.faces.resource/rafa.js.xhtml?ln=fr/default&v=1_01_2">
</script><link type="text/css" rel="stylesheet" href="/glassfish-ee/javax.faces.resource/css/rafa.css.xhtml?ln=fr/default&v=1_0" />
</head>
<body>
<div style="width:100%; text-align:center">
<form id="j_idt8" name="j_idt8" method="post" action="/glassfish-ee/ch5/ch5_12/index.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="j_idt8" value="j_idt8" />
<input type="submit" name="j_idt8:j_idt9" value="Rafa at Roland Garros" />
<input type="submit" name="j_idt8:j_idt10" value="Rafa at Wimbledon" />
<input type="submit" name="j_idt8:j_idt11" value="Rafa at US Open" />
<input type="submit" name="j_idt8:j_idt12" value="Rafa at Australian Open" />
<input type="hidden" name="javax.faces.ViewState" id="j_id1:javax.faces.ViewState:0" value="---somevalue---" autocomplete="off" />
</form>
</div>
<div style="width:100%; text-align:center">
<!--<h:graphicImage library="fr/default" name="img/rafa.png"/> -->
<img src="/glassfish-ee/javax.faces.resource/img/rafa.png.xhtml?ln=fr/default&v=1_0" />
</div>
</body>
</html>
呈现的 html 中感兴趣的相对 url-
http://localhost:8080/glassfish-ee/javax.faces.resource/rafa.js.xhtml?ln=fr/default&v=1_01_2
http://localhost:8080/glassfish-ee/javax.faces.resource/css/rafa.css.xhtml?ln=fr/default&v=1_0
http://localhost:8080/glassfish-ee/javax.faces.resource/img/rafa.png.xhtml?ln=fr/default&v=1_0
在控制台上,我得到了这个-
2016-06-08T20:54:52.672+0530|WARNING: JSF1064: Unable to find or serve resource, rafa.js, from library, fr/default.
2016-06-08T20:54:52.673+0530|WARNING: JSF1064: Unable to find or serve resource, css/rafa.css, from library, fr/default.
2016-06-08T20:54:52.717+0530|WARNING: JSF1064: Unable to find or serve resource, img/rafa.png, from library, fr/default.
2016-06-08T20:54:57.570+0530|WARNING: JSF1064: Unable to find or serve resource, css/rafa.css, from library, fr/default.
2016-06-08T20:56:05.587+0530|WARNING: JSF1064: Unable to find or serve resource, img/rafa.png, from library, fr/default.
2016-06-08T20:56:09.542+0530|WARNING: JSF1064: Unable to find or serve resource, img/rafa.png, from library, fr/default.
谷歌浏览器的控制台标签显示-
所以最后,我哪里错了?
请建议。
在下面建议的答案的帮助下,进行了更改,
有一个条目-
javax.faces.resource.localePrefix=fr
1_2.js
使用 GET 请求访问页面时,由于文件中的以下条目而弹出警报,如selected
上面所附结构所示。
alert("J'ai gagné Roland Garros ...(resources/fr/1_0/css/js/rafa.js/1_2.js)");
locale
即使在我通过按所需的更改 后,我也会看到相同的警报弹出command button
。
为什么?还需要做什么?提前致谢。