BalusC は 100% 正しいですが、(彼が警告しているように) 彼の答えは役に立たないでしょう。ここで重要な点は、2 番目の Bean をまったく管理する必要がないことです。GUI ではなく、モデルです。おそらく次のようなものが必要でした:
@ManagedBean
@ViewScoped
class PeopleHolder {
private List<Person> people = new ArrayList<Person>();
// not managed at all:
private Person currentPerson;
// just the getter, no need for a setter
public Person getCurrentPerson() { return currentPerson; }
@PostConstruct
public init(){ currentPerson = new Person(); }
public void addCurrentPersonToList() {
people.add(currentPerson);
init();
}
// just for test:
public List<People> getPeople() { return people; }
}
そして今フォーム:
<h:form>
<h:inputText value="#{peopleHolder.currentPerson.name}" />
<h:inputText value="#{peopleHolder.currentPerson.lastName}" />
<h:commandButton action="#{peopleHolder.addCurrentPersonToList}" />
</h:form>