i have implemented PrimeFaces selectOneMenu through github and PrimeFaces and not clear about why themeservice-bean has been defined as Application scope e.g.
@Named
@ApplicationScoped
public class ThemeService {
private List<Theme> themes;
@PostConstruct
public void init() {
themes = new ArrayList<>();
themes.add(new Theme(0, "Nova-Light", "nova-light"));
themes.add(new Theme(1, "Nova-Dark", "nova-dark"));
themes.add(new Theme(2, "Nova-Colored", "nova-colored"));
themes.add(new Theme(3, "Luna-Blue", "luna-blue"));
themes.add(new Theme(4, "Luna-Amber", "luna-amber"));
themes.add(new Theme(5, "Luna-Green", "luna-green"));
themes.add(new Theme(6, "Luna-Pink", "luna-pink"));
themes.add(new Theme(7, "Omega", "omega"));
}
public List<Theme> getThemes() {
return themes;
}
}
in my view, the same bean should be defined as View/Request scoped as the list may need to be populated with different records, but as i change the scope it gives error of
java.lang.NullPointerException
at org.primefaces.showcase.convert.ThemeConverter.getAsObject(ThemeConverter.java:27)
at return statement in converter
ThemeService service = (ThemeService) fc.getExternalContext().getApplicationMap().get("themeService");
return service.getThemes().get(Integer.parseInt(value));
may somebody shed some light on this.