本文介绍了Ajax无法正常工作的JSF 2.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将JSF 2.2与TomCat 6一起使用.当我执行ajax函数时,不会更新字段.我创建了一个只有一个控制器和一个页面的新项目,即使如此,ajax调用也不起作用.它会调用该方法,但不会更新页面.
I'm using JSF 2.2 with TomCat 6. When I execute an ajax function the fields are not updated. I created a new project with just one controller and page even so, the ajax calls doesn't work.It calls the method but doesn't update the page.
<!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:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:rich="http://richfaces.org/rich" xmlns:a4j="http://richfaces.org/a4j" xmlns:ajax="https://ajax4jsf.dev.java.net/ajax">
<h:head>
</h:head>
<h:body>
<h:form id="formTest">
<h:outputLabel value="#{teste.teste}" id="testando" />
<h:inputText value="#{teste.teste}" />
<a4j:commandButton action="#{teste.agir}" render="formTest" execute="formTest" />
</h:form>
</h:body>
</html>
控制器:
@ManagedBean(name = "teste")
@SessionScoped
public class Teste {
private String teste = "oi";
public void agir() {
teste = "666666";
System.out.println(getTeste());
}
public String getTeste() {
return teste;
}
public void setTeste(String teste) {
this.teste = teste;
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Try</display-name>
<welcome-file-list>
<welcome-file>index.jsf</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
</web-app>
推荐答案
Tomcat 6基于Servlet 2.5规范,而JSF 2.2需要Servlet 3.0. Tomcat版本为7.x分支,或将JSF实现版本降级为2.1.x.
Tomcat 6 is based in Servlet 2.5 spec, while JSF 2.2 requires Servlet 3.0. Don't get puzzled by it, upgrade your Tomcat version to 7.x branch or downgrade the JSF implementation version to 2.1.x.
另请参见:
这篇关于Ajax无法正常工作的JSF 2.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!