Note that there are some explanatory texts on larger screens.

plurals
  1. POjsf/primefaces load indicator during init of the bean
    primarykey
    data
    text
    <p>In my JSF/Primefaces project, I have a lot of data loading in the init (postconstruct) method of my beans. That's why I would like to show an gif indicator during the bean load.</p> <p>I tried with primefaces and the Ajax status (programmatic version of the showcase)</p> <pre><code>http://www.primefaces.org/showcase/ui/ajaxStatusScript.jsf </code></pre> <p>So I added this to the template of my project</p> <pre><code>&lt;p:dialog modal="true" widgetVar="loadWidget" header="Status" draggable="false" closable="false"&gt; &lt;p:graphicImage value="../images/ajaxload.gif" /&gt; &lt;/p:dialog&gt; </code></pre> <p>I would like to be able to call <code>loadWidget.show();</code> at the beginning of the init method of my bean and <code>loadWidget.hide();</code> at the end.</p> <p>Do you have an idea where and how to fire the javascript to display the loading gif? Thanks</p> <p><strong>EDIT</strong></p> <p>I could add that I tried this. Here is the part of my template that include the content of the page. It's not working either the p:dialog is included before or after the content.</p> <pre><code>&lt;div class="content"&gt; &lt;script&gt;loadWidget.show();&lt;/script&gt; &lt;ui:insert name="body" /&gt; &lt;script&gt;loadWidget.hide();&lt;/script&gt; &lt;/div&gt; </code></pre> <p>The console says <code>loadWidget is not defined</code></p> <p><strong>EDIT2</strong></p> <p>I will try to explain how my project works. Could be helpful.</p> <p>Here is my template</p> <pre><code>&lt;html ... &gt; &lt;f:view contentType="text/html"&gt; &lt;h:head&gt; ... &lt;/head&gt; &lt;h:body&gt; &lt;ui:insert name="header" /&gt; &lt;ui:insert name="menu" /&gt; &lt;ui:insert name="body" /&gt; &lt;ui:insert name="footer" /&gt; ... &lt;!-- Other things --&gt; &lt;/h:body&gt; &lt;/f:view&gt; &lt;/html&gt; </code></pre> <p>Then each page defines the <code>body</code>. Example of a page.</p> <pre><code>&lt;html ... &gt; &lt;ui:composition template="myTemplateAbove"&gt; &lt;ui:define name="body"&gt; &lt;h:outputText value="#{beanOfMyFirstPage.myText}" /&gt; &lt;p:commandButton action="#{beanOfMyFirstPage.goToAnotherPage}" /&gt; ... &lt;/ui:define&gt; &lt;/ui:composition&gt; &lt;/html&gt; </code></pre> <p>Then each page is linked to a bean that extends a BaseBean.</p> <pre><code>@ManagedBean(name = "beanOfMyFirstPage") @ViewScoped public class beanOfMyFirstPage extends BaseBean { // attributes + getters and setters @PostConstruct public void init() { super.init(); ... // actions that take time cause of DB requests for example } public void goToAnotherPage() { navigation.handleNavigation(FacesContext.getCurrentInstance(), null, "mySecondPage"); } // methods } </code></pre> <p>And the common bean</p> <pre><code>public class BaseBean { @PostConstruct public void init() { super.init(); // General actions for all beans } } </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