0

please help me to understand,

<h:form>
  <h:panelGrid columns="3">
    <h:outputText value="Age:"/>
    <h:inputText value="#{userBean.age}" size="4"/>
    <a4j:commandButton value="Enter Age" reRender="age"/>
  </h:panelGrid>
  <h:panelGrid>
    <h:outputText id="age" value="Your age: #{userBean.age}"/>
  </h:panelGrid>
</h:form>

when commandButton is clicked, how it evaluates a bean to call setters for. is it getting refrance from the bean used inside the input area?

thanks

muneebShabbir
  • 2,500
  • 4
  • 29
  • 46

1 Answers1

8

The command button does not do that. The command button only determines for itself if an action has to be invoked and if so, which method it is. Each of the input components sets their own value. The actual job is done in the decode() method of the Renderer associated with the component. During the apply request values phase, JSF walks through all UIForm, UIInput and UICommand components. Each of them first gets the request parameter value by own client ID as request parameter name:

String value = request.getParameter(input.getClientId(context));

(the request is here HttpServletRequest and input is here UIInput)

Then, after a process of conversion and validation where necessary, it get ultimately set as bean property referenced by its own value attribute.

input.getValueExpression("value").setValue(context.getElContext(), value);

The ValueExpression#setValue() will evaluate the #{userBean.age}, auto-create the bean if it doesn't exist in the scope yet and then invoke the setAge() method on it with the passed-in value.

This is all in detail described in the JSF specification.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555