I’m trying to wrap my head around some basic JSF 2 concepts. For instance, if I have a managed bean, Bean1:
@ManagedBean
public class Bean1 {
private String foo;
private String bar;
}
and the values for foo and bar are obtained from a JSF web form. On each submit of the web form, I want to store an instance of Bean1 in a Java Collection of another bean:
@ManagedBean
public class Bean2 {
private List<Bean1> beanList;
}
What is the correct way to achieve this? Thanks.
Make
Bean2a managed property ofBean1so that you have access to itsbeanListproperty.(please note that this way just the reference is stored, not a clone of the
Bean1‘s state or something!)Needless to say that this is a design smell. There are likely better ways to achieve the concrete functional requirement which you’ve had in mind while asking the question but didn’t tell anything about. In the future try to ask how to solve the functional requirement instead of how to achieve a solution (which may not be the right solution after all).