I have used mainly the first option, but I came upon the second option, and it seems to do everything faster with less code. Which way is better for creating forms using JSF? Is there a better option for creating form for an application with many server and client side validations? I really do not like to have a constructor like new Person()
. What would you advise me? Thank you.
Option 1:
View:
<h:inputText value=#{bean.fisrtName}/>
<h:inputText value=#{bean.lastName}/>
<h:commandButton action=#{bean.submit()}/>
Bean
private firstName;
private lastName;
public String submit(){
Person person = new Person(firstName, lastName);
// do something with person
}
Option 2:
View
<h:inputText value=#{bean.person.fisrtName}/>
<h:inputText value=#{bean.person.lastName}/>
<h:commandButton action=#{bean.submit()}/>
Bean
private Person person
@PostConstruct
public void init(){
person = new Peson();
}
public String submit(){
// do something with person
}