JSF 2 Ajax 请求在 IE 9 上失败
我最近尝试在 IE9 上测试我的 JSF 应用程序,发现所有 Ajax 请求都会失败,并在尝试访问 removeChild 属性时出现 MalformedXML 异常,抱怨未定义的对象。我观察到 MyFaces 2.0.5 和 mojarra 2.1.1 都存在问题。支持 IE 9 是否有任何已知的限制或先决条件?
为了重现这个问题,我将其归结为一个由一个 ajax 请求组成的简单测试用例:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<f:view contentType="text/html">
<h:head>
<h:outputScript name="jsf.js" library="javax.faces" target="head"/>
</h:head>
<h:body>
<h:form id="#{testBean.idForm}">
<h1>Test of IE9 Ajax</h1>
<h:panelGroup id="#{testBean.idDiv}" layout="block">
Text: <h:outputText value="#{testBean.text}"/>
<br/>
<h:commandLink
action="#{testBean.onAction}"
value="click me">
<f:ajax render="#{testBean.idDiv}"/>
</h:commandLink>
</h:panelGroup>
</h:form>
</h:body>
</f:view>
</html>
该 bean 是
package ietest;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class TestBean {
private int clickCount;
private String idForm="testForm";
private String idDiv="testDiv";
public String getText(){
String text = "you clicked " + clickCount +" times";
System.out.println("Return text " + text);
return text;
}
public String onAction(){
System.out.println("onAction invoked");
clickCount++;
return "iebug";
}
public String getIdDiv() {
return idDiv;
}
public String getIdForm() {
return idForm;
}
}
I recently tried to test my JSF application on IE9 and discovered all Ajax requests to fail with a MalformedXML exception complaining about an undefined object when trying to access the removeChild attribute. I observed the problems both with MyFaces 2.0.5 and mojarra 2.1.1. Are there any known limitiations or prerequisites to support IE 9?
To reproduce the problem I nailed it down to a simple test case consisting of one ajax request:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<f:view contentType="text/html">
<h:head>
<h:outputScript name="jsf.js" library="javax.faces" target="head"/>
</h:head>
<h:body>
<h:form id="#{testBean.idForm}">
<h1>Test of IE9 Ajax</h1>
<h:panelGroup id="#{testBean.idDiv}" layout="block">
Text: <h:outputText value="#{testBean.text}"/>
<br/>
<h:commandLink
action="#{testBean.onAction}"
value="click me">
<f:ajax render="#{testBean.idDiv}"/>
</h:commandLink>
</h:panelGroup>
</h:form>
</h:body>
</f:view>
</html>
The bean is
package ietest;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class TestBean {
private int clickCount;
private String idForm="testForm";
private String idDiv="testDiv";
public String getText(){
String text = "you clicked " + clickCount +" times";
System.out.println("Return text " + text);
return text;
}
public String onAction(){
System.out.println("onAction invoked");
clickCount++;
return "iebug";
}
public String getIdDiv() {
return idDiv;
}
public String getIdForm() {
return idForm;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来像 Mojarra 问题 JAVASERVERFACES-1981。
Looks like Mojarra issue JAVASERVERFACES-1981.
在 Tomcat 7.0.12 上使用 Mojarra 2.1.1 无法重现此问题。
您的问题是由其他原因引起的。我怀疑在您的真实代码中错误地使用了动态 ID,就像您在
#{testBean.idDiv}
中所使用的那样。尝试使用固定的 id(为什么要使其动态化?)此外,
完全是多余的,默认情况下 JSF 已经包含了这个。将其删除。如果它使问题变得更大,那么它肯定是由其他原因引起的,例如不同 JSF 版本混合在一起的脏类路径。Cannot reproduce this problem using Mojarra 2.1.1 on Tomcat 7.0.12.
Your problem is caused by something else. I suspect it's in your real code an incorrect use of dynamic ids as you have with
#{testBean.idDiv}
. Try it with fixed ids (why would you ever make it dynamic?)Further, the
<h:outputScript>
is entirely superfluous, this one is already by default included by JSF. Remove it. If it makes the problem bigger, then it is definitely caused by something else, e.g. a dirty classpath of different JSF versions mixed altogether.