Handles data response from JSF Ajax in Javascript -


i have follow managed bean class:

  import javax.faces.bean.managedbean;   import javax.faces.bean.sessionscoped;    import java.io.serializable;    @managedbean   @sessionscoped   public class hellobean implements serializable {  private static final long serialversionuid = 1l;  private string name;  public string getname() {     return name; }  public void setname(string name) {     this.name = name; }  public string getsaywelcome(){     //check if null?     if("".equals(name) || name ==null){         return "";     }else{         return "ajax message : welcome " + name;     }    }  } 

and jsf file:

<?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:f="http://java.sun.com/jsf/core"         xmlns:h="http://java.sun.com/jsf/html">  <h:body>     <h3>jsf 2.0 + ajax hello world example</h3>      <h:form>          <h:inputtext id="name" value="#{hellobean.name}"></h:inputtext>         <h:commandbutton value="welcome me">              <f:ajax execute="name" onevent="example" render="output" />         </h:commandbutton>          <h2><h:outputtext id="output" value="#{hellobean.saywelcome}" /></h2>      </h:form>  </h:body> 

and javascript function call when ajax response has been completed receive data parameter:

function ejemplo(data){         $('#tablaejemplo').append('<table><thead><tr><th>user</th></tr></thead>'+                                    '<tbody><tr><td>'+data.name+'</td></tr></tbody>           </table>');         } 

my pretensions when ajax response success, print table username of manage bean inserted in input text don't know how access parameter (the data.name doesn't work) print, don't know if f:ajax returning or have set in place (i guess in manage bean...) format json data retrieve , can access in function, no?. ideas?

if want show name, why not adding ajax rendered part :

<h:commandbutton value="welcome me">     <f:ajax render="output" /> </h:commandbutton>  <h2><h:outputtext id="output" value="#{hellobean.saywelcome} #{hellobean.name}" /></h2> 

if name null not show @ all.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -