What is the correct way to bind an input value to a JSF-controlled bean property?

I am new to JSF and managed beans. I have a managed bean with some private property with public installers and Getter methods. Now that I am adding managed beans to JSF forms, should I directly add private methods or use property calls with the Getter method?

For instance:

  • <h:inputText value="#{BeanName.userName}"/>
  • <h:inputText value="#{BeanName.getUserName()}"/>

Which one is true above?

+3
source share
3 answers

, JBoss EL EL 2.2+, . , get , set . , . EL ( ) getUserName() setUserName(), .

, JSF EL, .

JSF, - JSF.

+4

java -

....
private String coolStuff;

public String getCoolStuff() {
    return coolStuff;
}
....

jsf :

#{myBackingBean.coolStuff}

getCoolStuff()

,

+1

number 1 is correct above, this is a private field that you connect if you use EL with JSF in your form.

You still need the getter and setter that the managed bean calls to get the values ​​so you can store them in the database .... etc

0
source

Source: https://habr.com/ru/post/1751635/


All Articles