动态调用消息包?
我有一个非常简单的 JSF 2.0 项目。
我有一个 index.xhtml 文件来向我展示拉什莫尔山的图片。 在此页面上,我可以单击图片,然后将其转到“president.xhtml” - 没问题。一个简单的操作=“”...
我的问题是我的消息包文件(messages.properties)是使用静态键和值设置的,例如:
jeffersonPageTitle=Thomas Jefferson
rooseveltPageTitle=Theodore Roosevelt
lincolnPageTitle=Abraham Lincoln
washingtonPageTitle=George Washington
在我的“president.xhtml”文件中,我希望它显示这些标题取决于我点击的内容。
<h:form>
<span class="presidentPageTitle">#{msgs['rushmore.president'],PageTitle}</span>
<br />
<h:graphicImage library="images" name="jefferson.jpg" styleClass="leftImage" />
<span class="presidentDiscussion">#{msgs.washingtonDiscussion}</span>
<br />
<h:commandLink action="index" styleClass="backLink">${msgs.indexLinkText}</h:commandLink>
</h:form>
上面代码中的第二行是我的问题 - 我不知道如何在我的 java 代码中引用 get-Method 。代码在这里:
@ManagedBean // or @Named
@RequestScoped
public class Rushmore {
private String outcome = null;
private Rectangle washingtonRect = new Rectangle(70, 30, 40, 40);
private Rectangle jeffersonRect = new Rectangle(115, 45, 40, 40);
private Rectangle rooseveltRect = new Rectangle(135, 65, 40, 40);
private Rectangle lincolnRect = new Rectangle(175, 62, 40, 40);
public Rushmore() {}
public void handleMouseClick(ActionEvent e) {
FacesContext context = FacesContext.getCurrentInstance();
String clientId = e.getComponent().getClientId(context);
Map<String, String> requestParams = context.getExternalContext().getRequestParameterMap();
int x = new Integer((String) requestParams.get(clientId + ".x")).intValue();
int y = new Integer((String) requestParams.get(clientId + ".y")).intValue();
outcome = null;
if (washingtonRect.contains(new Point(x, y))) {
outcome = "washington";
}
if (jeffersonRect.contains(new Point(x, y))) {
outcome = "jefferson";
}
if (rooseveltRect.contains(new Point(x, y))) {
outcome = "roosevelt";
}
if (lincolnRect.contains(new Point(x, y))) {
outcome = "lincoln";
}
System.out.println(requestParams.keySet());
}
public String getPresident() {
return outcome;
}
public String navigate() {
if(outcome != null) {
return "president";
}
else return null;
}
}
这是我试图在 President.xhtml 文件中访问的 getPresident 方法...
任何帮助将不胜感激:)
I have a very simple JSF 2.0 project.
I have an index.xhtml file to show me a picture of Mount Rushmore.
On this page, I can click on the picture and I want it to go to "president.xhtml" - no problem in that. A simple action=""...
My problem is that my message bundle file (messages.properties) is set up with static keys and values, ex.:
jeffersonPageTitle=Thomas Jefferson
rooseveltPageTitle=Theodore Roosevelt
lincolnPageTitle=Abraham Lincoln
washingtonPageTitle=George Washington
And in my "president.xhtml" file, I want it to show these titles depending on what I clicked on.
<h:form>
<span class="presidentPageTitle">#{msgs['rushmore.president'],PageTitle}</span>
<br />
<h:graphicImage library="images" name="jefferson.jpg" styleClass="leftImage" />
<span class="presidentDiscussion">#{msgs.washingtonDiscussion}</span>
<br />
<h:commandLink action="index" styleClass="backLink">${msgs.indexLinkText}</h:commandLink>
</h:form>
Second line in the code above is my problem - I don't know how to refer to the get-Method in my java-code. Code is here:
@ManagedBean // or @Named
@RequestScoped
public class Rushmore {
private String outcome = null;
private Rectangle washingtonRect = new Rectangle(70, 30, 40, 40);
private Rectangle jeffersonRect = new Rectangle(115, 45, 40, 40);
private Rectangle rooseveltRect = new Rectangle(135, 65, 40, 40);
private Rectangle lincolnRect = new Rectangle(175, 62, 40, 40);
public Rushmore() {}
public void handleMouseClick(ActionEvent e) {
FacesContext context = FacesContext.getCurrentInstance();
String clientId = e.getComponent().getClientId(context);
Map<String, String> requestParams = context.getExternalContext().getRequestParameterMap();
int x = new Integer((String) requestParams.get(clientId + ".x")).intValue();
int y = new Integer((String) requestParams.get(clientId + ".y")).intValue();
outcome = null;
if (washingtonRect.contains(new Point(x, y))) {
outcome = "washington";
}
if (jeffersonRect.contains(new Point(x, y))) {
outcome = "jefferson";
}
if (rooseveltRect.contains(new Point(x, y))) {
outcome = "roosevelt";
}
if (lincolnRect.contains(new Point(x, y))) {
outcome = "lincoln";
}
System.out.println(requestParams.keySet());
}
public String getPresident() {
return outcome;
}
public String navigate() {
if(outcome != null) {
return "president";
}
else return null;
}
}
It's the getPresident method I'm trying to reach in the president.xhtml file...
Any help would be much appreciated :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
c:set
。
Use
c:set
.