I just edited the question. Well I already made the menu but without hibernate better said with jdbc. but at the time of deploying the project does not show me the menu with hibernate I will leave the tables.
I'm working with netbeans and when doing with hibernate, they generate the classes in a model package.
now in the dao.
public interface relacionDao { public List listRelation (); }
in the daoImpl
public class relacionDaoImpl implements relacionDao {
@Override
public List<Relacion> listarRelacion() {
List<Relacion> lista=null;
Session session=HibernateUtil.getSessionFactory().openSession();
Transaction t=session.beginTransaction();
String hql="From Relacion";
try{
lista=session.createQuery(hql).list();
t.commit();
session.close();
}catch(Exception e){
t.rollback();
}
return lista;
}
on the bean.
@Named // @ ManagedBean @SessionScoped public class relacionBean implements Serializable {
private List<Relacion> lista;
private Relacion relacion = new Relacion();
private MenuModel model;
private relacionDaoImpl relaciondao = new relacionDaoImpl();
@PostConstruct
public void init() {
this.listarMenus();
model = new DefaultMenuModel();
this.establecerPermisos();
}
public void listarMenus() {
try {
lista = relaciondao.listarRelacion();
} catch (Exception e) {
}
}
public MenuModel getModel() {
return model;
}
public void setModel(MenuModel model) {
this.model = model;
}
public void establecerPermisos() {
Empleado lg = (Empleado) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("empleado");
for (Relacion m : lista) {
if (!m.getSubmenu().isProcesado()) {
int actual = m.getSubmenu().getMenu().getIdMenu();
if (m.getSubmenu().getMenu().getTipo().equals("S") && m.getEmpleado().getCodEmpleado() == lg.getCodEmpleado()) {
DefaultSubMenu firstSubMenu = new DefaultSubMenu(m.getSubmenu().getMenu().getNomMenu());
for (Relacion i : lista) {
if (actual == i.getSubmenu().getMenu().getIdMenu() && !i.getSubmenu().isProcesado()) {
Submenu submenu = i.getSubmenu();
Empleado empleado = i.getEmpleado();
if (submenu != null) {
if (submenu.getMenu().getIdMenu() == m.getSubmenu().getMenu().getIdMenu() && empleado.getCodEmpleado() == m.getEmpleado().getCodEmpleado()) {
DefaultMenuItem item = new DefaultMenuItem(i.getSubmenu().getNombreSubMenu());
item.setUrl(i.getSubmenu().getLinkSubMenu());
firstSubMenu.addElement(item);
i.getSubmenu().setProcesado(true);
}
}
}
}
model.addElement(firstSubMenu);
m.getSubmenu().setProcesado(true);
} else if (m.getSubmenu().getMenu().getIdMenu() != m.getSubmenu().getIdSubMenu() && m.getEmpleado().getCodEmpleado() == lg.getCodEmpleado()) {
DefaultMenuItem item = new DefaultMenuItem(m.getSubmenu().getMenu().getNomMenu());
item.setUrl(m.getSubmenu().getLinkSubMenu());
model.addElement(item);
}
}
}
}
in the xhtml template.
Facelets Template
<h:body>
<div id="top" >
<ui:insert name="top">
<h:form>
<p:menubar model="#{relacionBean.model}"/>
</h:form>
</ui:insert>
</div>
<div id="content" class="center_content">
<ui:insert name="content">Content</ui:insert>
</div>
<div id="bottom">
<ui:insert name="bottom">Bottom</ui:insert>
</div>
</h:body>
making the display does not show me the menu. but when I do it with JDBC if it generates the menu I hope you excuse me but a little I do not understand hibernate thank you very much.