I am starting in JSF2, comming from spring mvc, so I have some doubts that I cannot find answers on Core JavaServer Faces v3
Like this one…
How can the tag h:commandButton know which bean I am talking about ? I can only have one Bean per JSF page, is that it ? I am only giving it a msg.next which is a text from a i18n file.(quizbean is my bean)
<h:body>
<h:form>
<h3>#{msgs.heading}</h3>
<p>
<h:outputFormat value="#{msgs.currentScore}">
<f:param value="#{quizBean.score}"/>
</h:outputFormat>
</p>
<p>#{msgs.guessNext}</p>
<p>#{quizBean.current.sequence}</p>
<p>
#{msgs.answer}
<h:inputText value="#{quizBean.answer}"/>
</p>
<p><h:commandButton value="#{msgs.next}"/></p>
</h:form>
The command button does not need to know this. All it generates is a HTML
<input type="submit">element. This is embedded in a HTML<form>with an action URL pointing to the same URL as the page. There’s further also the<input type="hidden" name="javax.faces.ViewState">. Thanks to this field, JSF knows exactly what view you’re submitting to. This view holds information about all inputs. This view knows that there’s an<h:inputText value="#{quizBean.answer}" />. The view knows the fieldnameof the generated HTML<input type="text">element. JSF will get the submitted request parameter value byrequest.getParameter()using this name and then update theanswerproperty of the current instance ofquizBeanwith this value.Rightclick the page in your browser and choose View Source to see the JSF-generated HTML output. Put a breakpoint on
ApplyRequestValuesPhase#execute()andHtmlBasicRenderer#decode()methods (assuming that you’re using Mojarra not MyFaces) to track the gathering of submitted values for everyUIComponentin the view.