2
我有一個名爲人模型類和視圖範圍內託管bean PersonController包含設置託管bean屬性從複合材料部件
我創建了取人的這個列表中的複合材料部件的人名單。什麼?我想要做的是設置在其他託管bean的人員名單稱爲TestCompositeComponent直接從複合材料部件。任何解決方案。這是我的代碼:
@ManagedBean
@ViewScoped
public class PersonController {
private List<Person> persons;
public List<Person> getPersons() {
return persons;
}
public void setPersons(List<Person> persons) {
this.persons = persons;
}
@PostConstruct
public void init() {
persons = new ArrayList<>();
Person person1 = new Person();
person1.setFirstname("blah");
person1.setLastname("blah");
Person person2 = new Person();
person2.setFirstname("blah");
person2.setLastname("blah");
persons.add(person1);
persons.add(person2);
}
}
@ManagedBean
@ViewScoped
public class TestCompositeComponentController {
private List<Person> persons;
public List<Person> getPersons() {
return persons;
}
public void setPersons(List<Person> persons) {
this.persons = persons;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite">
<composite:interface componentType="testCompositeController">
<composite:attribute name="persons" />
</composite:interface>
<composite:implementation>
<h:outputText value="composite"></h:outputText>
</composite:implementation>
</html>
<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:test="http://java.sun.com/jsf/composite/test"
xmlns:f="http://java.sun.com/jsf/core">
<h:head></h:head>
<h:body>
<test:test persons="#{personController.persons}" />
</h:body>
</html>
「@ Inject」不是CDI唯一的註釋嗎?它也可以使用'@ ManagedProperty'嗎? – mabi
我的建議是讓你在TestCompositeComponentController中獨立處理人員,最後通過CDI更新PersonController。 – Yamada