8

私はこの投稿を知っており、そこでのすべての可能性を再確認しました。

Glassfish3にMojarraを実装したJSF2.0を使用しています。

<h:commandLink>2つの単純なタグを使用して、アプリケーションの言語を変更しようとしています。これは.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スクリプトエラーがスローされます。

クロサギは定義されていません

Beanメソッドは正しく呼び出され、アプリケーションの残りの部分で正常に機能します。

4

2 に答える 2

7

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;
}
于 2012-02-13T15:32:23.483 に答える
1

Try to watch what happens in Firebug or something similiar, to see if there is actually a server communication. And since it is a commandLink, look if there are any javascript errors on the page.

You say, you don't get any INFO logs, so I think the request doesn't even get to your application.

(I don't see a closing html tag in your xhtml file, maybe you just didn't pasted it.)

于 2012-02-12T16:07:47.263 に答える