Note that there are some explanatory texts on larger screens.

plurals
  1. POjava.lang.NullPointerException at org.primefaces.context.RequestContext.getCurrentInstance
    primarykey
    data
    text
    <p>I used a RequestContext's primeFaces object in a managed bean method in order to execute some javascript from the server side. I used to do this inside a Listener handler method (a method with an AjaxBehaviourEvent parameter handling requests from <code>f:ajax</code> tags) and it works but this time i used a method without any parameters.</p> <p>The problem is that i m appending some html with jquery .append() and had to use jquery ajax to send requests to server from added elements (i can't append any jsf components because they won't work as they are not generated by jsf itself) so I had to use bean methods without parameters and call that method from a servlet which handle ajax comming resquests.</p> <p>to explain this more in details, suppose i add html code with jquery this way : </p> <pre><code>$('#substartmenudiv').append('&lt;div id="congesdiv" /&gt;'); </code></pre> <p>and then add the code which must be executed once the new added div is clicked :</p> <pre><code>$('#congesdiv').click(function(){ $.post('AjaxRelaisServlet',{action:"setstrtmenustatus",startmenuisopen:startmenuisopen}); }); </code></pre> <p>and from the servlet i catch parameters sent by the ajax request and call the bean method :</p> <pre><code>protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { boolean startmenuisopen= Boolean.valueOf(request.getParameter("startmenuisopen")); UserBean.testcmdlink(startmenuisopen); </code></pre> <p>the called testcmdlink bean method contains the RequestContext object, it looks like this : </p> <pre><code>public static void testcmdlink(boolean startmenuisopen){ RequestContext context = RequestContext.getCurrentInstance(); if(!startmenuisopen){ context.execute("$('#substartmenudiv').append('&lt;div id="+"gestprofdiv"+" /&gt;');"); context.execute("displaymenuitems();"); context.execute("console.log('more elements are appended !!');"); startmenuisopen=true; }else{ context.execute("$('#substartmenudiv').empty();"); context.execute("window['bottomvalue'] =30;"); context.execute("console.log('start menu div is emptied !!');"); startmenuisopen=false; } } </code></pre> <p>Is there a way to make it work anywhere ? </p> <p>cheers !</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.
 

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