单击h:commandLink会导致未捕获的ReferenceError:未定义mojarra [英] Clicking h:commandLink causes Uncaught ReferenceError: mojarra is not defined
问题描述
我知道这个帖子,我仔细检查过所有的可能性。
我在Glassfish 3上使用JSF 2.0和Mojarra实现。
<我正在尝试使用两个简单的
< h:commandLink>
标签来更改应用程序语言。 这是
.xhtml
页面: < !DOCTYPE html>
< html lang =enxmlns =http://www.w3.org/1999/xhtml
xmlns:f =http://java.sun.com/jsf/核心
xmlns:h =http://java.sun.com/jsf/html>
< h:head>
< title>
< h:outputText value =#{appMessage ['page.welcome']}/>
< / title>
< f:元数据>
< f:event type =preRenderViewlistener =#{sessionController.changeLanguage}/>
< / f:元数据>
< / 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 =enxmlns =http://www.w3.org/1999/xhtml>
< head>
< title>迷宫项目< / title>
< / head>
< body>
< h1>欢迎< / h1>
< form id =fm-languagename =fm-languagemethod =postaction =/ maze / welcome.xhtmlenctype =application / x-www-form-urlencoded> ;
< input type =hiddenname =fm-languagevalue =fm-language/>
< script type =text / javascriptsrc =/ 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'},'' );返回false>英文< / a>
< a href =#onclick =mojarra.jsfcljs(document.getElementById('fm-language'),{'fm-language:j_idt15':'fm-language:j_idt15'},'' );返回false> Deutsch< / a>
< input type =hiddenname =javax.faces.ViewStateid =javax.faces.ViewStatevalue =8038443616162706480:-1387069664590476821autocomplete =off/>
< / form>
< / body>
当按下commandLink时没有任何内容一切都好了。没有发送到服务器的请求,并且抛出以下Java脚本错误:
mojarra未定义
正确调用bean方法,并在其余的应用程序中正常工作。
源和生成的HTML输出看起来很好,你在JSF源中有一个< h:head>
(否则JSF无法使用自动包含任何CSS / JS文件),HTML输出中存在 javax.faces:jsf.js
脚本。
你说,你得到一个JS错误, mojarra
没有被定义。这只能意味着以下自动生成的脚本
< script type =text / javascriptsrc =/ maze / javax.faces.resource / jsf.js.xhtml?ln = javax.faces>
< / script>
未产生有效回复。这反过来只意味着你有一个过滤器
,它映射在 / *
或 *。xhtml
以某种方式限制 jsf.js
资源请求。也许一些本土的身份验证过滤器没有完全正确地完成其工作。尝试打开
http:// localhost:8080 / maze / javax.faces.resource / jsf.js.xhtml?ln = javax.faces
在浏览器中查看它实际检索到的内容(或使用Web开发人员工具检查响应)。如果它确实不是正确的响应并且问题确实存在于过滤器
中,那么您可能需要重写它以便在请求URI开始时它应该继续链 ResourceHandler.RESOURCE_IDENTIFIER
。
例如
HttpServletRequest req =(HttpServletRequest)请求;
if(req.getRequestURI()。startsWith(req.getContextPath()+ ResourceHandler.RESOURCE_IDENTIFIER)){
chain.doFilter(request,response); //让它继续
返回;
}
I am aware of this post and I double checked all the possibilities there.
I'm using JSF 2.0 with Mojarra implementation on Glassfish 3.
I'm trying to use two simple <h:commandLink>
tags to change the application language.
This is the .xhtml
page:
<!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>
This is the HTML code:
<!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>
When pressing a commandLink nothing at all happens. There is no request sended to the server and this following Java Script error is thrown:
mojarra is not defined
The bean methods are correctly called and work fine in the rest of the appliction.
The source and generated HTML output looks fine, you have there a <h:head>
in the JSF source (otherwise JSF wasn't able to auto-include any CSS/JS files), and the javax.faces:jsf.js
script is present in the HTML output.
You said, you got a JS error that mojarra
is not definied. That can only mean that the following auto-generated script
<script type="text/javascript" src="/maze/javax.faces.resource/jsf.js.xhtml?ln=javax.faces">
</script>
did not result in a valid response. That can in turn only mean that you've a Filter
which is mapped on /*
or *.xhtml
which is restricting the jsf.js
resource request in some way. Perhaps some homegrown authentication filter which is not doing its job entirely right. Try opening
http://localhost:8080/maze/javax.faces.resource/jsf.js.xhtml?ln=javax.faces
in your browser to see what it actually retrieved (or use the web developer tools to check the response). If it's indeed not the proper response and the problem is indeed in the Filter
, then you probably need to rewrite it as such that it should continue the chain when the request URI starts with ResourceHandler.RESOURCE_IDENTIFIER
.
E.g.
HttpServletRequest req = (HttpServletRequest) request;
if (req.getRequestURI().startsWith(req.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) {
chain.doFilter(request, response); // Let it continue.
return;
}
这篇关于单击h:commandLink会导致未捕获的ReferenceError:未定义mojarra的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!