Pressing h: commandLink raises an Uncaught ReferenceError: mojarra undefined

I know this post, and I double-checked all the features there.

I am using JSF 2.0 with a Mojarra implementation on Glassfish 3.

I am trying to use two simple <h:commandLink> to change the language of the application. 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 you click the commandLink button, nothing happens. The server does not receive a request, and the following Java Script error occurs:

mojarra not defined

The bean methods call correctly and work fine in the rest of the application.

+8
javascript undefined jsf mojarra commandlink
source share
2 answers

The source and generated HTML output looks great, you have the <h:head> source in the JSF source (otherwise JSF was not able to automatically add CSS / JS files), and the javax.faces:jsf.js script is present in the HTML output.

You said that you have a JS error that is not defined. This can only mean the following auto-generated script.

 <script type="text/javascript" src="/maze/javax.faces.resource/jsf.js.xhtml?ln=javax.faces"> </script> 

did not lead to a valid answer. This may mean that you have a Filter that maps to /* or *.xhtml , which somehow restricts the request to the jsf.js resource. Perhaps some kind of built-in authentication filter that does not do its job completely correctly. Try to open

http: // localhost: 8080 / maze / javax.faces.resource / jsf.js.xhtml? ln = javax.faces

in your browser to find out what it really received (or use web developer tools to check the answer). If this is really not the right answer and the problem really is in Filter , then you probably have to rewrite it as such so that it continues the chain when the request URI starts with ResourceHandler.RESOURCE_IDENTIFIER .

eg.

 HttpServletRequest req = (HttpServletRequest) request; if (req.getRequestURI().startsWith(req.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) { chain.doFilter(request, response); // Let it continue. return; } 
+5
source share

Try to see what is happening in Firebug or something similar to see if there really is a connection to the server. And since this is commandLink, see if there are any javascript errors on the page.

You say that you do not receive any INFO logs, so I think the request does not even get into your application.

(I do not see the closing html tag in your xhtml file, maybe you just didn’t paste it.)

+1
source share

All Articles