0

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>
Aritz
  • 30,971
  • 16
  • 136
  • 217
Victor Bello
  • 493
  • 1
  • 8
  • 23

1 Answers1

3

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:

Community
  • 1
  • 1
Aritz
  • 30,971
  • 16
  • 136
  • 217
  • Thanks man. It worked, I thought It was working with 2.2 and tomcat 6 because everything worked but Ajax. I have another question... when I execute the project I got 404 (localhost:8080/Try) I have to insert manually "index.jsf" to work. I downgrade to 2.1.x But this still happens. Any Idea? – Victor Bello Feb 05 '14 at 11:55
  • 1
    Don't use `*.jsf` extensions. If you're actually at JSF 2, use facelets, with `*.xhtml`. Take care of changing your url-pattern to `*.xhtml` at web.xml. – Aritz Feb 05 '14 at 11:57