Board index JavaServer Faces General simpliest ajax example wouldn't work

simpliest ajax example wouldn't work

Components, Ajax Framework, Utilities and More.


Posts: 85
Location: Tunisia
as am trying to test a simple ajax example from the user guide, well, it didn't work here the code :
index.xhtml :
<?xml version='1.0' encoding='UTF-8' ?>
<!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:p="http://primefaces.prime.com.tr/ui">

    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <h:inputText id="firstname" value="#{bean.firstname}">
            <p:ajax event="keyup" update="out" />
        </h:inputText>
        <h:outputText id="out" value="#{bean.firstname}" />
    </h:body>
</html>




bean.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package web;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author mouadh
 */
@ManagedBean(name="bean")
@SessionScoped
public class bean {
    private String firstname;
    /** Creates a new instance of bean */
    public bean() {
    }

    /**
     * @return the firstname
     */
    public String getFirstname() {
        return firstname;
    }

    /**
     * @param firstname the firstname to set
     */
    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

}



web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <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>/faces/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>



am i missing something or what???
Ben Khalifa Mouadh
engineering student at National School of Computer Sciences - Tunisia
JSF 2.0, GlassFish v3, PF 2.0.1,Majorra 2.0.2, netBeans 6.8


Posts: 85
Location: Tunisia
sorry but i forget to post the problem:
so this example is supposed to show the text while is tiped in the input text but it didn't.
Last edited by mouadh on 05 Jul 2010, 14:40, edited 1 time in total.
Ben Khalifa Mouadh
engineering student at National School of Computer Sciences - Tunisia
JSF 2.0, GlassFish v3, PF 2.0.1,Majorra 2.0.2, netBeans 6.8


Posts: 85
Location: Tunisia
i add a command button with ajax submit and it worked fine for updating the outputText but the <p:ajax ...> doesn't work???
any ideas?
Ben Khalifa Mouadh
engineering student at National School of Computer Sciences - Tunisia
JSF 2.0, GlassFish v3, PF 2.0.1,Majorra 2.0.2, netBeans 6.8


Posts: 85
Location: Tunisia
same problem with PF 2.0.2
Ben Khalifa Mouadh
engineering student at National School of Computer Sciences - Tunisia
JSF 2.0, GlassFish v3, PF 2.0.1,Majorra 2.0.2, netBeans 6.8


Posts: 240
Location: Belgium
place <h:form prependId="false"> around this code
        <h:inputText id="firstname" value="#{bean.firstname}">
            <p:ajax event="keyup" update="out" />
        </h:inputText>
        <h:outputText id="out" value="#{bean.firstname}" />

like this
<h:form prependId="false">
        <h:inputText id="firstname" value="#{bean.firstname}">
            <p:ajax event="keyup" update="out" />
        </h:inputText>
        <h:outputText id="out" value="#{bean.firstname}" />
</h:form>
JSF-2.0, mojarra-2.0.2-FCS and PrimeFaces-2.1 on GlassFish v3.0.1 (build 22)


Posts: 15075
Location: Cybertron

Yes, you need a form as michiel suggested, prependId is optional though.
PrimeFaces Lead


Posts: 85
Location: Tunisia
thanks for replying,i add the form as you said but it still not working :( .
<?xml version='1.0' encoding='UTF-8' ?>
<!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:p="http://primefaces.prime.com.tr/ui">

    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <h:form prependId="false">
            <h:inputText id="firstname" value="#{bean.firstname}">
                <p:ajax event="keyup" update="out" />
            </h:inputText>
            <h:outputText id="out" value="#{bean.firstname}" />
        </h:form>
    </h:body>
</html>
Ben Khalifa Mouadh
engineering student at National School of Computer Sciences - Tunisia
JSF 2.0, GlassFish v3, PF 2.0.1,Majorra 2.0.2, netBeans 6.8


Posts: 240
Location: Belgium
define <f:view>
like:

<?xml version="1.0" encoding="UTF-8"?>
<!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" xml:lang="en" lang="en"
        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:p="http://primefaces.prime.com.tr/ui">
<f:view contentType="text/html">
<h:head>
   ....
</h:head>

   <h:body>
      ...
   </h:body>
</f:view>
</html>
JSF-2.0, mojarra-2.0.2-FCS and PrimeFaces-2.1 on GlassFish v3.0.1 (build 22)


Posts: 85
Location: Tunisia
that didn't work either. this the rendred html code that i get if that might help :

<?xml version='1.0' encoding='UTF-8' ?>
<!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"><head>
<script type="text/javascript" src="/ajax/primefaces_resource/2.0.1/yui/utilities/utilities.js"></script>
<script type="text/javascript" src="/ajax/primefaces_resource/2.0.1/jquery/jquery.js"></script>
<script type="text/javascript" src="/ajax/primefaces_resource/2.0.1/primefaces/core/core.js"></script>
        <title>Facelet Title</title></head><body>
<form id="j_idt7" name="j_idt7" method="post" action="/ajax/faces/index.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="j_idt7" value="j_idt7" />
<input id="firstname" type="text" name="firstname" /><span id="out"></span><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="-961534961503165008:-4534410868143990561" autocomplete="off" />
</form></body>
</html>
Ben Khalifa Mouadh
engineering student at National School of Computer Sciences - Tunisia
JSF 2.0, GlassFish v3, PF 2.0.1,Majorra 2.0.2, netBeans 6.8


Posts: 240
Location: Belgium
JSF-2.0, mojarra-2.0.2-FCS and PrimeFaces-2.1 on GlassFish v3.0.1 (build 22)

Next

Return to General