I have a backing bean as following:
@Named
@RequestScoped
public class ClientNewBackingBean {
@Inject
private ClientFacade facade;
private Client client;
The Client
class has a List<Child> childrenList
attribute, among others. I'm able to create a new Client
when setting the childrenList
with new ArrayList()
.
In the view, I have a input text field and an Add Child
button. The button has the attribute actionListener=#{clientNewBackingBean.addChild()}
implemented as:
public void addChild() {
if(client.getChildrenList() == null) {
client.getChildrenList(new ArrayList());
}
Child c = new Child("John Doe");
client.getChildrenList().add(c);
}
Everytime the Add Child
button is clicked, the bean is recreated and the view only shows one John Doe child (due to it being Request scoped, I believe). Is there another way to solve this besides changing the bean scope to Session?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…