Note that there are some explanatory texts on larger screens.

plurals
  1. PObinding objects initialization in JSF
    text
    copied!<p>I have this bean in application scope. </p> <pre><code>public class User { private UICommand link; private String name; public User(){ System.out.println("User.User()"); name = "Test Link"; } public UICommand getLink() { System.out.println("User.getLink()"); System.out.println(link==null?"link is null":"link is not null"); return link; } public void setLink(UICommand link) { System.out.println("User.setLink()"); this.link = link; System.out.println("link: "+link.toString()); } public void change(){ System.out.println("User.change()"); } //setter and getter for name } </code></pre> <p>I have this jsf on jsp page.</p> <pre><code>&lt;f:view&gt; &lt;h:form&gt; &lt;h:commandLink binding="#{user.link}" action="#{user.change}" value="#{user.name}"/&gt; &lt;/h:form&gt; &lt;/f:view&gt; </code></pre> <p>I thought that the UICommand object would be reused (by sending the serialized state of the object along with the HTML output) and thus maintain the state and binding. But I get this sysoutput.</p> <pre><code>//When page loads User.User() User.getLink() link is null User.setLink() link: javax.faces.component.html.HtmlCommandLink@14e4ce7 //when user clicks the link User.setLink() link: javax.faces.component.html.HtmlCommandLink@6fcc9c User.change() </code></pre> <p><code>UICommand</code> object is different each time the user clicks the link!!! Also i believe <code>getLink()</code> runs only once when that object is first loaded on page but if that's the case then the page woudn't reflect the latest UICommand object!</p>
 

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