Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing return value from bean function using JSF 2.0 Ajax response?
    primarykey
    data
    text
    <p>I'm builiding a scheduling application using JSF 2.0 where users can add items to a calendar then edit those objects.</p> <p>I'm using AJAX quite extensively to keep the page from refreshing.</p> <p>The problem I am having is to get a return value from the function that is called using AJAX.</p> <pre><code>&lt;!-- ... form to fill --&gt; &lt;h:commandButton value="Insert"&gt; &lt;f:ajax execute="formField1 formField2..." listener="#{myBean.insert()}" onevent="processSave"/&gt; &lt;/h:commandButton&gt; </code></pre> <p>This successfully calls my JavaScript function <code>processSave()</code>.</p> <p><code>myBean.insert()</code> returns the <code>id</code> of the newly inserted row in the database</p> <pre><code>public String insert() { //... inserting data into database id = {id from database is obtained here} System.out.println("I have the ID here : " id); //this works return id; } </code></pre> <p>I've been trying to get this from the response object within JavaScript in the <code>processSave()</code> function.</p> <pre><code>processSave(data) { if(data.status == "begin") { // ation done here } else if(data.status == "complete") { // more actions done here } else if(data.status == "success") { //I am trying to get the ID here //I've tried looking into data.responseXML, but to no avail. } } </code></pre> <p>Is what I am trying possible using the current technologies?</p> <p>I think it would be possible to have a field in the page updated using the <code>render</code> component of the AJAX call, then use Javascript to go get the value. But I'm thinking this wouldn't be as clean?</p> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload