simpliest ajax example wouldn't work

Components, Ajax Framework, Utilities and More.
User avatar
mouadh
Posts: 85
Joined: 27 Apr 2010, 12:47
Location: Tunisia

05 Jul 2010, 14:18

as am trying to test a simple ajax example from the user guide, well, it didn't work here the code :
index.xhtml :

Code: Select all

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

Code: Select all

/*
 * 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

Code: Select all

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

User avatar
mouadh
Posts: 85
Joined: 27 Apr 2010, 12:47
Location: Tunisia

05 Jul 2010, 14:22

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

User avatar
mouadh
Posts: 85
Joined: 27 Apr 2010, 12:47
Location: Tunisia

05 Jul 2010, 14:40

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

User avatar
mouadh
Posts: 85
Joined: 27 Apr 2010, 12:47
Location: Tunisia

05 Jul 2010, 15:19

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

User avatar
michiel
Posts: 240
Joined: 07 Jun 2010, 09:12
Location: Belgium

05 Jul 2010, 17:52

place <h:form prependId="false"> around this code

Code: Select all

        <h:inputText id="firstname" value="#{bean.firstname}">
            <p:ajax event="keyup" update="out" />
        </h:inputText>
        <h:outputText id="out" value="#{bean.firstname}" />
like this

Code: Select all

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

User avatar
optimus.prime
Prime
Posts: 17420
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

06 Jul 2010, 12:55

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

User avatar
mouadh
Posts: 85
Joined: 27 Apr 2010, 12:47
Location: Tunisia

09 Jul 2010, 13:52

thanks for replying,i add the form as you said but it still not working :( .

Code: Select all

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

User avatar
michiel
Posts: 240
Joined: 07 Jun 2010, 09:12
Location: Belgium

09 Jul 2010, 14:03

define <f:view>
like:

Code: Select all

<?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)

User avatar
mouadh
Posts: 85
Joined: 27 Apr 2010, 12:47
Location: Tunisia

09 Jul 2010, 14:20

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

Code: Select all


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

User avatar
michiel
Posts: 240
Joined: 07 Jun 2010, 09:12
Location: Belgium

09 Jul 2010, 14:38

JSF-2.0, mojarra-2.0.2-FCS and PrimeFaces-2.1 on GlassFish v3.0.1 (build 22)

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 6 guests