SelectOneMenu - Primefaces不在数据库中记录

时间:2015-08-04 21:35:28

标签: jsf primefaces selectonemenu

我正在使用Netbeans 8.0.1 - JSF 2.2 Primefaces 4.0 Hibernate 4.3.1

我尝试下拉,但我不明白,请为此我需要帮助,我认为一切都很好;我在这里显示我的代码:

XHTML:

<h:form id="formInsertar">
                <p:panelGrid columns="2">
                    <p:outputLabel value="Id:" />
                    <p:inputText value="#{vehiculoBean.vehiculo.idvehiculo}" disabled="true"/>
                    <p:outputLabel value="Tipo:" />
                    <p:selectOneMenu value="#{vehiculoBean.vehiculo.tipovehiculo}">
                        <f:selectItem itemLabel="-Seleccione-" itemValue=""/>
                        <f:selectItems value="#{tipoVehiBean.selectItemsTipoVehi}"/>
                    </p:selectOneMenu>
                    <p:outputLabel value="Marca:" />
                    <p:inputText value="#{vehiculoBean.vehiculo.marca}" />
                    <p:outputLabel value="Modelo:" />
                    <p:selectOneMenu value="#{vehiculoBean.vehiculo.modelo}">
                        <f:selectItem itemLabel="-Seleccione-" itemValue=""/>
                        <f:selectItems value="#{modeloBean.selectItemsmodelo}"/>
                    </p:selectOneMenu>
                    <p:outputLabel value="Color:" />
                    <p:selectOneMenu value="#{vehiculoBean.vehiculo.color}">
                        <f:selectItem itemLabel="-Seleccione-" itemValue=""/>
                        <f:selectItems value="#{colorBean.selectItemsColor}"/>
                    </p:selectOneMenu>
                    <p:outputLabel value="Año" />
                    <p:inputText value="#{vehiculoBean.vehiculo.anofabri}" />
                    <p:outputLabel value="Serie:" />
                    <p:inputText value="#{vehiculoBean.vehiculo.serie}" />
                    <p:outputLabel value="Motor:" />
                    <p:inputText value="#{vehiculoBean.vehiculo.motor}" />
                </p:panelGrid>
                <p:commandButton value="Crear" update=":formMostrar" actionListener="#{vehiculoBean.insertar()}" 
                                 oncomplete="dlginsertar.hide();" />
            </h:form>

我的豆子: VehiculoBean;

public vehiculoBean() {
}

public Vehiculo getVehiculo() {
    if(vehiculo == null){
        vehiculo = new Vehiculo();
    }
    return vehiculo;
}

public void setVehiculo(Vehiculo vehiculo) {
    this.vehiculo = vehiculo;
}

public List<Vehiculo> getVehiculos() {
    VehiculoDao tipodao = new VehiculoDaoImplements();
    vehiculos = tipodao.mostrarVehiculo();
    return vehiculos;
}

public void setVehiculos(List<Vehiculo> vehiculos) {
    this.vehiculos = vehiculos;
}

public void insertar (){
    VehiculoDao linkDao = new VehiculoDaoImplements();
    Date d = new Date();
    vehiculo.setFechareg(d);
    linkDao.insertarTipoVehiculo(vehiculo);
    vehiculo = new Vehiculo();

}

public void modificar(){
    VehiculoDao linkDao = new VehiculoDaoImplements();
    linkDao.modificarTipoVehiculo(vehiculo);
    vehiculo = new Vehiculo();
}

public void eliminar(){
    VehiculoDao linkDao = new VehiculoDaoImplements();
    linkDao.eliminarTipoVehiculo(vehiculo);
    vehiculo = new Vehiculo();
}

}

TipoVehiBean;

public class tipoVehiBean {

public Tipovehiculo vehiculo = new Tipovehiculo();
public List<Tipovehiculo> vehiculos;
private List<SelectItem> SelectItemsTipoVehi;

public tipoVehiBean() {
}

public Tipovehiculo getVehiculo() {
    return vehiculo;
}

public void setVehiculo(Tipovehiculo vehiculo) {
    this.vehiculo = vehiculo;
}

public List<Tipovehiculo> getVehiculos() {
    TipoVehiDao tipodao = new TipoVehiDaoImplements();
    vehiculos = tipodao.mostrarTipoVehiculo();
    return vehiculos;
}

public void setVehiculos(List<Tipovehiculo> vehiculos) {
    this.vehiculos = vehiculos;
}

public List<SelectItem> getSelectItemsTipoVehi() {
    this.SelectItemsTipoVehi = new ArrayList<SelectItem>();
    TipoVehiDao tipoVehiDao = new TipoVehiDaoImplements();
    List<Tipovehiculo> tipos = tipoVehiDao.mostrarTipoVehiculo();
    for (Tipovehiculo tipo : tipos) {
        SelectItem selecItem = new SelectItem(tipo.getIdtipovehiculo(),tipo.getNombre());
        this.SelectItemsTipoVehi.add(selecItem);
    }
    return SelectItemsTipoVehi;
}

public void insertar (){
    TipoVehiDao linkDao = new TipoVehiDaoImplements();
    Date d = new Date();
    vehiculo.setFechareg(d);
    linkDao.insertarTipoVehiculo(vehiculo);
    vehiculo = new Tipovehiculo();

}

public void modificar(){
    TipoVehiDao linkDao = new TipoVehiDaoImplements();
    linkDao.modificarTipoVehiculo(vehiculo);
    vehiculo = new Tipovehiculo();
}

public void eliminar(){
    TipoVehiDao linkDao = new TipoVehiDaoImplements();
    linkDao.eliminarTipoVehiculo(vehiculo);
    vehiculo = new Tipovehiculo();
}

}

我的道歉 VehiculoDao;

public class VehiculoDaoImplements implements VehiculoDao{

@Override
public List<Vehiculo> mostrarVehiculo() {
    Session session = null;
    List<Vehiculo> lista = null;
    try{
        session = HibernateUtil.getSessionFactory().openSession();
        Query query = session.createQuery("FROM Vehiculo");
        lista = (List<Vehiculo>)query.list();
    }catch (HibernateException e){
        System.out.println(e.getMessage());
    }
    finally{
        if (session != null){
            session.close();
        }
    }
    return lista;
}

@Override
public void insertarTipoVehiculo(Vehiculo vehiculo) {
    Session session = null;
    try {
        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        session.save(vehiculo);
        session.getTransaction().commit();
    } catch (HibernateException e){
        System.out.println(e.getMessage());
        session.getTransaction().rollback();
    }
    finally {
        if(session != null){
            session.close();
        }
    }
}

@Override
public void modificarTipoVehiculo(Vehiculo vehiculo) {
    Session session = null;
    try {
        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        session.update(vehiculo);
        session.getTransaction().commit();
    } catch (HibernateException e){
        System.out.println(e.getMessage());
        session.getTransaction().rollback();
    }
    finally {
        if(session != null){
            session.close();
        }
    }
}

@Override
public void eliminarTipoVehiculo(Vehiculo vehiculo) {
    Session session = null;
    try {
        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        session.delete(vehiculo);
        session.getTransaction().commit();
    } catch (HibernateException e){
        System.out.println(e.getMessage());
        session.getTransaction().rollback();
    }
    finally {
        if(session != null){
            session.close();
        }
    }
}

我做了所有这些并没有记录在数据库中;你能帮帮我吗?

0 个答案:

没有答案