I have a simple JSF2.0 from page as shown below:
<h:body>
<div><center><h1><big><u>Java Learning Center</u></big></h1></center></div>
<h2><big><a>Account Login</a></big></h2>
<h:outputText value="#{userBean.errorMessage}" style="color:red; text-size:20"/>
<h:form>
<h:panelGrid id="loginPanel" columns="3">
<h:outputText value="Username" />
<h:inputText value="#{userBean.username}" id="username" required="true" />
<h:message for="username" style="color:red; text-size:18"/>
<h:outputText value="Password" />
<h:inputSecret value="#{userBean.password}" id="password" required="true" />
<h:message for="password" style="color:red; text-size:18"/>
<h:commandButton value="Login" action="#{userBean.verifyUser()}" />
</h:panelGrid>
</h:form>
</h:body>
And the Corresponding JSF2 Bean class is as shown:
@ManagedBean(name="userBean")
@SessionScoped
public class UserBean {
private String username;
private String password;
private String errorMessage;
//setters and getters
public String verifyUser() {
//User verification logic
}
}
Now, when the form Page is rendered for the first time, I get the output in console as:
getErrorMessage()...
getUsername()...
getPassword()...
My Question is:
1. Why these getter methods are invoked even before submitting the form Page?
And when I am finally submitting the form page with values, then the console output is as follows:
getUsername()...
getPassword()...
setUsername()...
setPassword()...
verifyUser()...
Here,
2. Why the getters are invoked before setters ?. In my view the setters should be invoked first.