Note that there are some explanatory texts on larger screens.

plurals
  1. POajax call in jsf 2.0 (myfaces), the onevent Javascript function in the ajax tag gets called before the rendering is complete
    primarykey
    data
    text
    <p>This is my first time asking a question on a forum, since usually my questions have already been asked and answered. I haven't found an answer to this problem that works for me, so here goes:</p> <p>I'm making an Ajax call in JSF 2.0 like this:</p> <pre><code>&lt; f :ajax listener="#{myReferenceController.clearRequiredReferenceNumber}" onevent="resetFocus" execute="@form" render=":resultsForm:ResultsDisplay" /&gt; </code></pre> <p>Everything in the listener works perfectly, and the data is then rendered as expected in the data table that I have in my .xhtml page. The problem is that the Javascript that I call in the <code>onevent</code> seems to be getting called before the rendering is complete, and therefore the process of resetting the focus to a column in my <code>datatable</code> doesn't work, since the <code>datatable</code> is removed and then re-added to the DOM when the Ajax is finished re-rendering. </p> <p>I'm looking in my Javascript for the status of "success", in hopes that at this point, the rendering would have completed. Alas, this is not the case, and my <code>getElementById</code> (actually <code>dojo.byId</code>) is not finding the element in the datatable. I know my Javascript function works under normal circumstances, since I'm calling this same function in a situation where there is not an Ajax call, and everything works perfectly there.</p> <p>If I could just avoid rendering the cell in the table that I'm trying to set focus to, that would be great, but my listener is making changes to this cell in the ajax call. I'm at my wits end, so any ideas on this would be very appreciated.</p> <p>-- in response to Balusc (heard good things about you, btw)</p> <p>Hmm, I was actually on the right track I think, but still seem to be having troubles. I am checking for "success" and still even in success, am not able to set the focus here. Here's my Javascript function that is checking for "success": This function works in another situation, where it's not attached to an Ajax event.</p> <pre><code>function resetFocus(data) { var theRow = dojo.byId("resultsForm:selectedRow").value; if (data.status == "success") { dojo.query('[widgetId]',dojo.byId('theResultsDataTable')) .forEach(function(node) { var widget = dijit.byNode(node); var theId = widget.attr("id") if (theId.indexOf(':' + theRow + ':') != -1) { if (theId.indexOf('theOrppoNum') != -1) { widget.focus(); widget.attr("isFocused",true); } } }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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