Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is the getter called so many times by the rendered attribute?
    primarykey
    data
    text
    <p>Related to a previous example, i tried to monitor my get/set methods on the server (when they are called, and how often). So, my actual been look such :</p> <pre><code>@ManagedBean(name="selector") @RequestScoped public class Selector { @ManagedProperty(value="#{param.profilePage}") private String profilePage; public String getProfilePage() { if(profilePage==null || profilePage.trim().isEmpty()) { this.profilePage="main"; } System.out.println("GET "+profilePage); return profilePage; } public void setProfilePage(String profilePage) { this.profilePage=profilePage; System.out.println("SET "+profilePage); } } </code></pre> <p>and the only page who can call this method (it only calls the get method on rendered) is :</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;ui:composition xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets"&gt; &lt;h:panelGroup layout="block" id="profileContent"&gt; &lt;h:panelGroup rendered="#{selector.profilePage=='main'}"&gt; // nothing at the moment &lt;/h:panelGroup&gt; &lt;/h:panelGroup&gt; &lt;/ui:composition&gt; </code></pre> <p>my stupor when i see the server log, and i see :</p> <pre><code>SET null GET main GET main GET main GET main GET main GET main GET main </code></pre> <p>What? It call seven times the <code>getProfilePage()</code> method? (and also 1 time <code>setProfilePage()</code>) I would like to know why this behaviour :)</p> <p>Thanks</p> <p><strong>ADDED AN EXAMPLE</strong></p> <p>Bean</p> <pre><code>@ManagedBean(name="selector") @RequestScoped public class Selector { @ManagedProperty(value="#{param.profilePage}") private String profilePage; @PostConstruct public void init() { if(profilePage==null || profilePage.trim().isEmpty()) { this.profilePage="main"; } } public String getProfilePage() { return profilePage; } public void setProfilePage(String profilePage) { this.profilePage=profilePage; } } </code></pre> <p><code>profile.xhtml</code></p> <pre><code>&lt;h:panelGroup layout="block" id="profileContent"&gt; &lt;h:panelGroup layout="block" styleClass="content_title"&gt; Profilo Utente &lt;/h:panelGroup&gt; &lt;h:panelGroup rendered="#{selector.profilePage=='main'}"&gt; &lt;ui:include src="/profile/profile_main.xhtml" /&gt; &lt;/h:panelGroup&gt; &lt;h:panelGroup rendered="#{selector.profilePage=='edit'}"&gt; &lt;ui:include src="/profile/profile_edit.xhtml" /&gt; &lt;/h:panelGroup&gt; &lt;/h:panelGroup&gt; // profile_main.xhtml &lt;h:form id="formProfileMain" prependId="false"&gt; &lt;h:panelGroup layout="block" styleClass="content_span"&gt; &lt;h:outputScript name="jsf.js" library="javax.faces" target="head" /&gt; &lt;h:panelGroup layout="block" styleClass="profilo_3"&gt; &lt;h:commandButton value="EDIT"&gt; &lt;f:setPropertyActionListener target="#{selector.profilePage}" value="edit" /&gt; &lt;f:ajax event="action" render=":profileContent"/&gt; &lt;/h:commandButton&gt; &lt;/h:panelGroup&gt; &lt;/h:panelGroup&gt; &lt;/h:form&gt; // profile_edit.xhtml &lt;h:form id="formProfileEdit" prependId="false"&gt; &lt;h:panelGroup layout="block" styleClass="content_span"&gt; &lt;h:outputScript name="jsf.js" library="javax.faces" target="head" /&gt; &lt;h:panelGroup layout="block" styleClass="profilo_3"&gt; &lt;h:commandButton value="Edit"&gt; &lt;f:setPropertyActionListener target="#{selector.profilePage}" value="editProfile" /&gt; &lt;f:ajax event="action" render=":profileContent"/&gt; &lt;/h:commandButton&gt; &lt;h:commandButton value="Back"&gt; &lt;f:setPropertyActionListener target="#{selector.profilePage}" value="main" /&gt; &lt;f:ajax event="action" render=":profileContent"/&gt; &lt;/h:commandButton&gt; &lt;/h:panelGroup&gt; &lt;/h:panelGroup&gt; &lt;/h:form&gt; </code></pre> <p>In this example, i call the profile_main (as default); After (for example) I call profile_edit (by clicking on EDIT); After, I return to profile_main by clicking Back. Now, if i want to reload profile_edit (EDIT), i need to click many times on that command button. Why?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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