Note that there are some explanatory texts on larger screens.

plurals
  1. POOrder of execution of f:event causing exception
    primarykey
    data
    text
    <p>I am trying to run f:event when the page loads. <code>f:event</code> is associated with the backing bean function <code>init()</code>. The <code>init()</code> creates the session object <code>toIndex</code> which is used in the <code>getStatusList()</code> function. But the problem that I am facing is that the <code>getStatusList()</code> funciton is executed first and hence it cannot find the <code>toIndex</code> session object,and its giving me a null pointer exception. The <code>init()</code> function is never called. The <code>StatusBean</code> is session scoped.</p> <p>1)xhtml</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui" xmlns:c="http://java.sun.com/jsp/jstl/core"&gt; &lt;f:view&gt; &lt;f:event type="postAddToView" listener="#{statusBean.init}" &gt;&lt;/f:event&gt; &lt;/f:view&gt; &lt;h:head&gt;&lt;/h:head&gt; &lt;h:body&gt; &lt;c:forEach var="p" items="#{statusBean.statusList}" varStatus="loop"&gt; //content &lt;/c:forEach&gt; &lt;/h:body&gt; &lt;/html&gt; </code></pre> <p>2) Backing bean</p> <pre><code>public class StatusBean { public List&lt;Status&gt; getStatusList() { FacesContext context = FacesContext.getCurrentInstance(); HttpSession session = (HttpSession) context.getExternalContext() .getSession(true); User user = (User) session.getAttribute("userdet"); Query query = em.createQuery("SELECT s FROM Status s WHERE s.email='" + user.getEmail() + "' ORDER BY s.timeMillis desc", Status.class); List&lt;Status&gt; results = query.getResultList(); Collections.sort(results); int toIndex = (int) session.getAttribute("toIndex"); List&lt;Status&gt; subList = results.subList(0, toIndex); return subList; } public void init(ComponentSystemEvent event) { System.out.println("inside init"); FacesContext context = FacesContext.getCurrentInstance(); HttpSession session = (HttpSession) context.getExternalContext().getSession(true); int toIndex = 5; session.setAttribute("toIndex",toIndex); } } </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.
    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