0
<h:form>
    First Name: <h:inputText value="#{studentFormBean.fname}" /> <br/><br/>
    Last Name: <h:inputText value="#{studentFormBean.lname}" /> <br/><br/>
    Country : 
    <h:selectOneMenu value="#{studentBean.country}">
        <f:selectItem itemValue="Brazil" itemLabel="Brazil" />
        <f:selectItem itemValue="US" itemLabel="US" />
        <f:selectItem itemValue="UK" itemLabel="UK" />
        <f:selectItem itemValue="Myanmar" itemLabel="Myanmar" />
    </h:selectOneMenu>
    <h:commandButton value="Submit" action="FormResponse"/>
</h:form>

At this code, "#{studentFormBean.fname}" should point to setFname() in StudentFormBean.java but it point to getFname(). Why is this happened and how can I solve it?

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
LinMyat
  • 11

1 Answers1

1

#{studentFormBean.fname} will use both the getter and setter if used in an editable value holder like h:inputText. It will get the current value when the input is rendered. It will set the submitted when the for is submitted (and validation and conversion have passed).

See also:

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
  • I think the setter will be already invoked at validation-phase even though the model will not be updated if validation fails. – L. Monty Jun 02 '21 at 07:42