简体   繁体   中英

Ajax not working JSF 2.2

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>

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM