【发布时间】:2012-03-04 02:50:48
【问题描述】:
我知道this 的帖子,我仔细检查了那里的所有可能性。
我在 Glassfish 3 上使用带有 Mojarra 实现的 JSF 2.0。
我正在尝试使用两个简单的<h:commandLink> 标签来更改应用程序语言。
这是.xhtml 页面:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>
<h:outputText value = "#{appMessage['page.welcome']}" />
</title>
<f:metadata>
<f:event type = "preRenderView" listener = "#{sessionController.changeLanguage}" />
</f:metadata>
</h:head>
<h:body>
<h1><h:outputText value = "#{appMessage['text.slide.welcome']}" /></h1>
<h:form id = "fm-language">
<h:commandLink action = "#{sessionController.changeLanguage('en')}" value = "#{appMessage['link.english']}" />
<h:commandLink action = "#{sessionController.changeLanguage('de')}" value = "#{appMessage['link.german']}" />
</h:form>
</h:body>
这是 HTML 代码:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>The Maze Project</title>
</head>
<body>
<h1>Welcome</h1>
<form id="fm-language" name="fm-language" method="post" action="/maze/welcome.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="fm-language" value="fm-language" />
<script type="text/javascript" src="/maze/javax.faces.resource/jsf.js.xhtml?ln=javax.faces">
</script>
<a href="#" onclick="mojarra.jsfcljs(document.getElementById('fm-language'),{'fm-language:j_idt13':'fm-language:j_idt13'},'');return false">English</a>
<a href="#" onclick="mojarra.jsfcljs(document.getElementById('fm-language'),{'fm-language:j_idt15':'fm-language:j_idt15'},'');return false">Deutsch</a>
<input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="8038443616162706480:-1387069664590476821" autocomplete="off" />
</form>
</body>
当按下 commandLink 时,什么都没有发生。没有向服务器发送请求,并抛出以下 Java Script 错误:
mojarra 没有定义
bean 方法被正确调用并在应用程序的其余部分中正常工作。
【问题讨论】:
-
我可以假设您已经在最小的视图模板中对此进行了测试吗? IE。在同一个
<h:body>内的<h:form>之外绝对没有别的东西?如果没有,请发布一个完整的 SSCCE。 -
@BalusC 我更新了问题。
-
乍一看还不错。
#{languageController}bean 是如何注解/注册的? -
@BalusC languageController 是 Session Scoped 中的一个 ManagedBean。还更新了问题以正确处理此详细信息。我觉得很奇怪,根本没有采取任何行动。
-
@BalusC 此外,如果 EL 中指定的方法不存在,我应该得到类似
action="#{nonexistent}": Identity 'nonexistent' was null and was unable to invoke的内容。奇怪的是,如果使用不存在的操作进行测试,这两个链接不会引发任何类型的错误。
标签: javascript jsf undefined mojarra commandlink