This content has been marked as final.
Show 3 replies
-
1. Re: Data Table problem
ilya_shaikovsky May 8, 2007 7:46 AM (in response to luuzz)post you? sources please
-
2. Re: Data Table problem
ilya_shaikovsky May 8, 2007 7:46 AM (in response to luuzz)Sorry, post your sources please..
-
3. Re: Data Table problem
luuzz May 8, 2007 7:58 AM (in response to luuzz)Sorry, Here they are :
xhtml file : (i am using facelets)<h:form> <rich:panel style="height:600px"> <a4j:outputPanel id="listReportsPanel"> <rich:dataTable value="#{explorationTreeFaceBean.reports}" var="report" title="Liste des groupes rapports" binding="#{explorationTreeFaceBean.dataTable}" align="center"> <f:facet name="header"> <rich:columnGroup> <rich:column> <h:outputText value="Titre"></h:outputText> </rich:column> <rich:column> <h:outputText value="Description"></h:outputText> </rich:column> <rich:column colspan="2"> <h:outputText value="Actions"></h:outputText> </rich:column> </rich:columnGroup> </f:facet> <rich:column> <h:outputText value="#{report.titre}"></h:outputText> </rich:column> <rich:column> <h:outputText value="#{report.description}"></h:outputText> </rich:column> <rich:column> <h:commandLink actionListener="#{explorationTreeFaceBean.retirerRapport}"> <t:graphicImage url="/templates/images/delete.gif" border="0" alt="Retirer" title="Retirer"/> <f:param value="delete" name="action" /> </h:commandLink> </rich:column> <rich:column> <h:commandLink actionListener="#{groupsFaceBean.edit}"> <t:graphicImage url="/templates/images/edit.gif" border="0" alt="Editer" title="Editer" /> <f:param value="edit" name="action" /> </h:commandLink> </rich:column> </rich:dataTable> </a4j:outputPanel> </rich:panel>
Beanpackage com.sintigroup.bi.exploration.facebeans; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; import javax.faces.component.UICommand; import javax.faces.event.ActionEvent; import javax.faces.model.SelectItem; import org.richfaces.component.html.HtmlDataGrid; import org.richfaces.component.html.HtmlDataTable; import com.sintigroup.bi.authentication.dao.UserDAO; import com.sintigroup.bi.authentication.model.User; import com.sintigroup.bi.authentication.utils.UserSession; import com.sintigroup.bi.common.facesbeans.BasicFaceBean; import com.sintigroup.bi.exploration.dao.ExploreReportsDAO; import com.sintigroup.bi.exploration.model.Dossier; import com.sintigroup.bi.exploration.utils.DossierDetails; import com.sintigroup.bi.exploration.utils.tree.ReportsExplorationRootTreeNode; import com.sintigroup.bi.exploration.utils.tree.UserTreeNode; import com.sintigroup.bi.publication.model.Report; public class ExplorationTreeFaceBean extends BasicFaceBean { UserTreeNode root; ExploreReportsDAO exploreReportsDAO; UserDAO userDAO; Dossier dossierCourant; List<Report> reports; List<SelectItem> accessibleReports; Report[] selectedReports = new Report[0]; String nouveauDossier; String nouveauDossierRacine; HtmlDataGrid table; HtmlDataTable dataTable; int gridColums; public int getGridColums() { int n = 1; int max = getReports().size(); n = Math.min(max, 4); return n; } public void setGridColums(int gridColums) { this.gridColums = gridColums; } public HtmlDataGrid getTable() { return table; } public void setTable(HtmlDataGrid table) { this.table = table; } public String getNouveauDossier() { return nouveauDossier; } public void setNouveauDossier(String nouveauDossier) { this.nouveauDossier = nouveauDossier; } public UserDAO getUserDAO() { return userDAO; } public void setUserDAO(UserDAO userDAO) { this.userDAO = userDAO; } public ExploreReportsDAO getExploreReportsDAO() { return exploreReportsDAO; } public void setExploreReportsDAO(ExploreReportsDAO exploreReportsDAO) { this.exploreReportsDAO = exploreReportsDAO; } public ReportsExplorationRootTreeNode getRoot() { int pK = ((UserSession)getHttpSession().getAttribute("userConnected")).getUserId(); User _user = null; try { _user = userDAO.findUserByPrimaryKey(pK); } catch(Exception e) { e.printStackTrace(); } return new ReportsExplorationRootTreeNode(_user,exploreReportsDAO); } public void setRoot(UserTreeNode root) { this.root = root; } public Dossier getDossierCourant() { return dossierCourant; } public void setDossierCourant(Dossier dossierCourant) { this.dossierCourant = dossierCourant; } public List<Report> getReports() { ArrayList<Report> _reports = new ArrayList<Report>(); try { Dossier temp = dossierCourant; _reports = new ArrayList<Report>(temp.getRapports()); } catch(Exception e) { e.printStackTrace(); } return _reports; } public void setReports(List<Report> reports) { this.reports = reports; } public void onSelect(ActionEvent ev) { Hashtable<String, Object> parametres = getActionParameters((UICommand)ev.getComponent()); String value = parametres.get("id").toString(); try { setDossierCourant(exploreReportsDAO.findDossierByPrimaryKey(Integer.parseInt(value))); } catch(Exception e) { } } public void ajouterSousDossier(ActionEvent e) { DossierDetails details = new DossierDetails(); details.setLibelle(nouveauDossier); int parent = getDossierCourant().getId(); int user = ((UserSession)getHttpSession().getAttribute("userConnected")).getUserId(); try { exploreReportsDAO.createDossier(details, user, parent); setNouveauDossier(""); } catch(Exception ex) { ex.printStackTrace(); } } public void ajouterDossierRacine(ActionEvent e) { DossierDetails details = new DossierDetails(); details.setLibelle(nouveauDossierRacine); int parent = -1; int user = ((UserSession)getHttpSession().getAttribute("userConnected")).getUserId(); try { exploreReportsDAO.createDossier(details, user, parent); setNouveauDossierRacine(""); } catch(Exception ex) { ex.printStackTrace(); } } public List<SelectItem> getAccessibleReports() { int user = ((UserSession)getHttpSession().getAttribute("userConnected")).getUserId(); ArrayList<SelectItem> _reports = new ArrayList<SelectItem>(); try { ArrayList<Report> reports = new ArrayList<Report>(exploreReportsDAO.findAccessibleReports(user)); for(Report report:reports) { SelectItem temp = new SelectItem(report,report.getTitre()); _reports.add(temp); } } catch(Exception e) { e.printStackTrace(); } return _reports; } public void setAccessibleReports(List<SelectItem> accessibleReports) { this.accessibleReports = accessibleReports; } public Report[] getSelectedReports() { return selectedReports; } public void setSelectedReports(Report[] selectedReports) { this.selectedReports = selectedReports; } public void ajouterRapport(ActionEvent e) { int parent = getDossierCourant().getId(); try { for(Report r:selectedReports) { exploreReportsDAO.addReportToDossier(r.getId(), parent); } } catch(Exception ex) { ex.printStackTrace(); } } public void retirerRapport(ActionEvent e) { int parent = getDossierCourant().getId(); try { //int report = ((Report) table.getRowData()).getId(); int report = ((Report) dataTable.getRowData()).getId(); exploreReportsDAO.deleteReportFromDossier(report, parent); setReports(getReports()); } catch(Exception ex) { ex.printStackTrace(); } } public void deleteDossier(ActionEvent e) { int parent = getDossierCourant().getId(); try { exploreReportsDAO.deleteDossier(parent); setDossierCourant(null); } catch(Exception ex) { ex.printStackTrace(); } } public String getNouveauDossierRacine() { return nouveauDossierRacine; } public void setNouveauDossierRacine(String nouveauDossierRacine) { this.nouveauDossierRacine = nouveauDossierRacine; } public HtmlDataTable getDataTable() { return dataTable; } public void setDataTable(HtmlDataTable dataTable) { this.dataTable = dataTable; } }
My Dao which delete an objectpackage com.sintigroup.bi.exploration.dao; import java.util.List; import java.util.Set; import java.util.Vector; import org.hibernate.HibernateException; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.springframework.orm.hibernate3.HibernateTemplate; import com.sintigroup.bi.authentication.dao.UserDAO; import com.sintigroup.bi.authentication.model.User; import com.sintigroup.bi.common.exceptions.OperationException; import com.sintigroup.bi.exploration.model.Dossier; import com.sintigroup.bi.exploration.utils.DossierDetails; import com.sintigroup.bi.publication.dao.ReportsDAO; import com.sintigroup.bi.publication.model.Report; public class ExploreReportsDAODefaultImpl extends HibernateTemplate implements ExploreReportsDAO { SessionFactory sessionFactory; UserDAO userDAO; ReportsDAO reportsDAO; public ReportsDAO getReportsDAO() { return reportsDAO; } public void setReportsDAO(ReportsDAO reportsDAO) { this.reportsDAO = reportsDAO; } public UserDAO getUserDAO() { return userDAO; } public void setUserDAO(UserDAO userDAO) { this.userDAO = userDAO; } public SessionFactory getSessionFactory() { return sessionFactory; } public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } public Dossier findDossierByPrimaryKey(int pK) throws OperationException { Dossier dossier = null; Session session = getSession(); try { dossier = (Dossier) session.get(Dossier.class, pK); } catch (HibernateException e) { throw new OperationException("sintibi", "dossiers", "GET"); } return dossier; } public List<Report> findRootReportsByUser(int userId) throws OperationException { List<Report> reports = null; List<Dossier> dossiers = null; Session session = getSession(); try { String hql = "from Report r where r not in ("; hql+= "select rap from Dossier d join d.rapports rap where d .proprietaire.id = "+userId; hql+= ")"; Query query = session.createQuery(hql); reports = query.list(); } catch (Exception e) { e.printStackTrace(); throw new OperationException("sintibi", "reports", "GET"); } return reports; } public void createDossier(DossierDetails details, int user, int parent) throws OperationException { Session session = getSession(); Dossier dossier = new Dossier(); dossier.fill(details); User u = userDAO.findUserByPrimaryKey(user); Dossier dossierParent = findDossierByPrimaryKey(parent); dossier.setDossierParent(dossierParent); if(dossierParent!=null) { dossierParent.getSousDossiers().add(dossier); } dossier.setProprietaire(u); if(u!=null) { u.getDossiers().add(dossier); } try { session.saveOrUpdate(dossier); } catch (Exception e) { e.printStackTrace(); throw new OperationException("sintibi", "dossiers", "INSERT"); } } public List<Dossier> findRootDossiersByUser(int userId) throws OperationException { List<Dossier> dossiers = null; Session session = getSession(); try { Query query = session.createQuery("from Dossier d where d.proprietaire.id = "+userId+" and d.dossierParent = null"); dossiers = query.list(); } catch (Exception e) { e.printStackTrace(); throw new OperationException("sintibi", "dossiers", "GET"); } return dossiers; } public void deleteReportFromDossier(int r, int d) throws OperationException { try { Session session = getSession(); Dossier dossier = (Dossier)session.get(Dossier.class, d); Report report = (Report)session.get(Report.class, r); if(dossier != null) { dossier.getRapports().remove(report); session.update(dossier); session.flush(); } } catch(Exception e) { e.printStackTrace(); } } public void addReportToDossier(int r, int d) throws OperationException { Session session = getSession(); Dossier dossier = (Dossier)session.get(Dossier.class, d); Report report = (Report)session.get(Report.class, r); if(dossier != null) { dossier.getRapports().add(report); session.flush(); } } public void addReportToFavoris(int r, int u) throws OperationException { Session session = getSession(); try { Report report = reportsDAO.findReportByPrimaryKey(r); User user = userDAO.findUserByPrimaryKey(u); user.getReportsFavoris().add(report); session.flush(); } catch (Exception e) { e.printStackTrace(); throw new OperationException("sintibi", "dossiers", "GET"); } } public List<Dossier> findAllDossiersByUser(int userId) throws OperationException { List<Dossier> dossiers = null; Session session = getSession(); try { Query query = session.createQuery("from Dossier d where d.proprietaire.id = "+userId); dossiers = query.list(); } catch (Exception e) { e.printStackTrace(); throw new OperationException("sintibi", "dossiers", "GET"); } return dossiers; } public Set<Report> findFavorisByUser(int u) throws OperationException { Set<Report> rapports = null; try { User user = userDAO.findUserByPrimaryKey(u); rapports = user.getReportsFavoris(); } catch (Exception e) { e.printStackTrace(); throw new OperationException("sintibi", "dossiers", "GET"); } return rapports; } public void deleteReportFromFavoris(int r, int u) throws OperationException { try { User user = userDAO.findUserByPrimaryKey(u); Report report = reportsDAO.findReportByPrimaryKey(r); user.getReportsFavoris().remove(report); Session session = getSession(); session.flush(); } catch (Exception e) { e.printStackTrace(); throw new OperationException("sintibi", "favoris", "GET"); } } public void deleteDossier(int d) throws OperationException { try { Dossier dossier = findDossierByPrimaryKey(d); Session session = getSession(); session.delete(dossier); session.flush(); } catch (Exception e) { e.printStackTrace(); throw new OperationException("sintibi", "favoris", "GET"); } } public List<Report> findAccessibleReports(int userId) throws OperationException { List<Report> reports = null; Session session = getSession(); try { String hql = "select distinct(report) from User u join u.groupes groupe join groupe.accessibleReports report "; hql+= "where u.id = :id"; Query query = session.createQuery(hql); query.setInteger("id", userId); reports = query.list(); } catch (Exception e) { e.printStackTrace(); throw new OperationException("sintibi", "reports", "GET"); } return reports; } public List<Report> findReport(String q, int userId) throws OperationException { // TODO Auto-generated method stub List<Report> reports = null; Session session = getSession(); try { String hql = "select report from User u join u.groupes groupe join groupe.accessibleReports report "; hql+= "where u.id = :id and "; hql+= "(report.keywords like '%"+q+"%' "; hql+= "or report.titre like '%"+q+"%' "; hql+= "or report.description like '%"+q+"%') "; Query query = session.createQuery(hql); query.setInteger("id", userId); reports = query.list(); } catch (Exception e) { e.printStackTrace(); throw new OperationException("sintibi", "reports", "GET"); } return reports; } }
It's long but i hope it helps. I am not sending faces-config.xml file.
I don't think this is the problem.
Thank for the quick reaction !!