java – SelectOneMenu is not powered


I have a p:selectOneMenu and would like it to be fed with existing data in the database as soon as the page is loaded:


<p:selectOneMenu id="carros">
    <f:selectItem itemLabel="Carros" itemValue="0"/>
    <f:selectItems value="#{menuManagedBean.carros}" var="carro" itemLabel="#{carro.modelo}" itemValue="#{carro}"/>

public class MeuManagedBean {

    private String modelo;
    private int codigo;
    private ArrayList<MeuManagedBean> carros;

    public void attCarros() {
        carros = new CarroDAO.metodoDAO();

public class CarroDAO {
    public ArrayList<MeuManagedBean> metodoDAO() {
        ResultSet rs //...
        ArrayList<MeuManagedBean> carros = new ArrayList<MeuManagedBean>();
        while ( {
            MeuManagedBean carro = new MeuManagedBean();
    return carros;

When I access the page, nothing appears in p:selectOneMenu . What do I have to fix to make it work?

I noticed a very strange behavior. Every time I try to add a method that is called immediately on the page (ie with a PostConstruct annotation or in the constructor itself) it doesn't work.

When I put a "MyManagedBean" object inside the cars ArrayList manually (by constructor using carros.add(MeuManagedBean) ), it appears in p:selectOneMenu .



public class MeuManagedBean {

public List< MeuManagedBean > getCarros(){

       return new CarroDAO().metodoDAO();


<f:selectItems value="#{menuManagedBean.carros}".../>

Notice the name you refer to the Bean in this menu and not mine.

Tip: Rename the methods according to their function, change medotoDAO to getCarros or listarCarros .

Scroll to Top