I have a bean with a field called 'name' and a JSF form that has an inputText mapped to this field. The initial value of the field is well displayed in the form.
The problem is when I submit the form, the value is not updated with the contents of inputText. In the savePlayer () method below, the value of the name is always the "name", not what I typed inside the form input.
bean:
@Named
@RequestScoped
public class PlayerForm {
@Inject
private PlayerRepository playerRepository;
private String name = "name";
public String savePlayer(){
Player player = new Player();
player.setName(name);
playerRepository.savePlayer(player);
return "saveUserOk";
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
The form:
<h:form>
<h:inputText value="#{playerForm.name}" />
<h:commandButton value="Submit" action="#{playerForm.savePlayer}" />
</h:form>
Thanks so much for any help!
source
share