将MyFaces 1.2迁移到2.1后,链接突然停止响应

时间:2012-02-22 14:36:19

标签: jsf myfaces

我最近将Eclipse Indigo项目从JSF 1.2切换到JSF 2.1(使用MyFaces)。使用Tomcat 7.

奇怪的事情发生了:我建立了一个项目,它的工作正常 时间,然后突然(也许在我做“干净”之后)在某种意义上停止工作 单击命令链接不会产生任何操作,支持bean的方法不会 叫,没有任何事情发生。我曾尝试做项目“干净”和Eclipse 重启,甚至系统重启但它没有帮助。唯一有帮助的是 我创建了一个全新的工作区和新项目 - 但同样的事情发生了: 这也只是在短时间内工作,突然停止工作同样的方式 - 命令链接只是对点击没有反应,我无法调试Java 代码至少本地化问题。

这种奇怪行为可能是什么原因?

提前致谢。


更新:这是报告的JavaScript错误:

myfaces is not defined
onclick()onclick (line 2)
event = click clientX=840, clientY=252

return myfaces.oam.submitForm("j_id_6", "j_id_6:LOGIN");

function onclick(event) {
return myfaces.oam.submitForm("j_id_6", "j_id_6:LOGIN");
}

这是原始的XHTML文件:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 
  xmlns:f="http://java.sun.com/jsf/core" 
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:t="http://myfaces.apache.org/tomahawk">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Login</title>    
</h:head>
<body style="background-color:#3d3d3d;" text="#000000" link="#cc0000" alink="#666666" vlink="#cc0000" onload="document.forms[0].USERNAME.focus();">
<f:view>

<h:form target="_top">

    <table border="0" align="center" width="810" style="border: 2px black solid; background-image:url(images/header.jpg); margin:auto;" cellspacing="0" cellpadding="0">
        <tr>

        </tr>
    </table>
    <table align="center" width="810" style="border: 2px black solid; background-color:#ffffff;" cellspacing="0" cellpadding="0">
        <tr>
            <td width="100%" height="10" colspan="3" align="center" valign="middle">

            </td>
        </tr>
        <tr>
            <td colspan="3">
            <table width="778" align="center" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td valign="top" width="778"><h1>Login</h1>
                        <table cellpadding="0" cellspacing="0" border="0">
                              <tr>                                  
                                <td height="20"><font class="text">User Name: </font></td>
                                <td height="20"><font class="text"><t:inputText forceId="true" id="USERNAME" maxlength="50" value="#{LoginBean.username}" size="26" /></font></td>
                            </tr>
                            <tr>
                                <td height="20"><font class="text">Password: </font></td>
                                <td height="20"><font class="text"><h:inputSecret maxlength="30" value="#{LoginBean.password}" size="26" /></font></td>
                            </tr>
                            <tr>
                                <td height="20" colspan="2" align="right"><h:commandLink id="LOGIN" action="#{LoginBean.doLogin}"><h:graphicImage style="border: none" value="images/login.png" /></h:commandLink></td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
            </td>
        </tr>
    </table>

</h:form>    

</f:view>
</body>
</html>

以下是生成的HTML:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Login</title></head>
<body style="background-color:#3d3d3d;" text="#000000" link="#cc0000" alink="#666666" vlink="#cc0000" onload="document.forms[0].USERNAME.focus();"><form id="j_id2030916047_790d5181" name="j_id2030916047_790d5181" method="post" action="/EWC/login.faces" enctype="application/x-www-form-urlencoded" target="_top">

    <table border="0" align="center" width="810" style="border: 2px black solid; background-image:url(images/header.jpg); margin:auto;" cellspacing="0" cellpadding="0">
        <tr>

        </tr>
    </table>

    <table align="center" width="810" style="border: 2px black solid; background-color:#ffffff;" cellspacing="0" cellpadding="0">
        <tr>
            <td width="100%" height="10" colspan="3" align="center" valign="middle">

            </td>
        </tr>
        <tr>
            <td colspan="3">
            <table width="778" align="center" border="0" cellspacing="0" cellpadding="0">
                <tr>

                    <td valign="top" width="778"><h1>Login</h1>
                        <table cellpadding="0" cellspacing="0" border="0">
                            <tr>                                    
                                <td height="20"><font class="text">User Name: </font></td>
                                <td height="20"><font class="text"><input id="USERNAME" name="USERNAME" type="text" value="" maxlength="50" size="26" /></font></td>
                            </tr>
                            <tr>
                                <td height="20"><font class="text">Password: </font></td>

                                <td height="20"><font class="text"><input type="password" name="j_id2030916047_790d5181:j_id2030916047_790d51ba" maxlength="30" size="26" /></font></td>
                            </tr>
                            <tr>
                                <td height="20" colspan="2" align="right"><script type="text/javascript" src="/EWC/javax.faces.resource/oamSubmit.js.faces?ln=org.apache.myfaces"></script><a href="#" onclick="return myfaces.oam.submitForm('j_id2030916047_790d5181','j_id2030916047_790d5181:LOGIN');" id="j_id2030916047_790d5181:LOGIN"><img src="images/login.png" style="border: none" /></a></td>
                            </tr>
                        </table>
                    </td>
                </tr>

            </table>
            </td>
        </tr>
    </table><input type="hidden" name="j_id2030916047_790d5181_SUBMIT" value="1" /><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="5s3ZqoVcUIwarcQb6pVzFIPhMJIzbVHnjMrXdtgA1Nten7grU/y0hMGbHtFvIExuKQOwB3IGzcSDeuPfijYMcnK23q/2N1mduMdr6RskySGELSaI2w93nL9b8NE=" /></form>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

<context-param> 
    <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>    
    <param-value>true</param-value> 
</context-param>

将其添加到Web.xml中 一切都将开始。