一尘不染

Ajax无法正常运行JSF 2.2

tomcat

我将JSF 2.2与TomCat
6一起使用。执行ajax函数时,不会更新字段。我创建了一个只有一个控制器和一个页面的新项目,即使如此,ajax调用也不起作用。它调用方法,但不更新页面。

    <!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>

阅读 265

收藏
2020-06-16

共1个答案

一尘不染

Tomcat 6基于Servlet 2.5规范,而JSF 2.2需要Servlet 3.0。
不用担心,将您的Tomcat版本升级到7.x分支或将JSF实现版本降级到2.1.x。

也可以看看:

2020-06-16