Ajax not working JSF 2.2

孤人 提交于 2019-12-13 06:28:27

问题


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>

Controller:

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

回答1:


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.

See also:

  • Apache Tomcat Version Details

  • What's new in JSF 2.2?

  • JSF-Servlet compatibility



来源:https://stackoverflow.com/questions/21575348/ajax-not-working-jsf-2-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!