[JSF] MyFaces - Composant tree

MyFaces - Composant tree [JSF] - Java - Programmation

Marsh Posté le 10-03-2006 à 15:31:52    

Bonjour,
 
J'ai un petit problème avec le tag "tree" de myFaces.
Il me génère bien la page mais jen'ai pas les images.
 
page JSP :  

Code :
  1. <%@ page session="true" contentType="text/html;charset=utf-8"%>
  2. <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
  3. <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
  4. <%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
  5. <html>
  6. <body>
  7. <f:view>
  8.     <t:tree id="tree" value="#{mytree.model}"
  9.          styleClass="tree"
  10.         nodeClass="treenode"
  11.          selectedNodeClass="treenodeSelected"
  12.          expandRoot="true">
  13.     </t:tree>
  14. </f:view>
  15. </body>
  16. </html>


 
et voici le bean MyTree associé :

Code :
  1. package test;
  2. import org.apache.myfaces.custom.tree.DefaultMutableTreeNode;
  3. import org.apache.myfaces.custom.tree.model.DefaultTreeModel;
  4. import org.apache.myfaces.custom.tree.model.TreeModel;
  5. public class MyTree {
  6. private TreeModel model;
  7. public MyTree() {
  8.  DefaultMutableTreeNode nodes = new DefaultMutableTreeNode("parent" );
  9.  DefaultMutableTreeNode a = new DefaultMutableTreeNode("A" );
  10.  DefaultMutableTreeNode b = new DefaultMutableTreeNode("B" );
  11.  DefaultMutableTreeNode c = new DefaultMutableTreeNode("C" );
  12.  DefaultMutableTreeNode d = new DefaultMutableTreeNode("D" );
  13.  nodes.insert(a);
  14.  nodes.insert(b);
  15.  nodes.insert(a);
  16.  nodes.insert(d);
  17.  model = new DefaultTreeModel(nodes);
  18. }
  19. public TreeModel getModel() {
  20.  return model;
  21. }
  22. }


 
et me produit le code html suivant :

Code :
  1. <html>
  2. <body>
  3. <table class="tree" border="0" cellspacing="0" cellpadding="0">
  4. <tr><td><a href="#" onclick="clear_linkDummyForm();document.forms['linkDummyForm'].elements['linkDummyForm:_link_hidden_'].value='tree_node_5';if(document.forms['linkDummyForm'].onsubmit){document.forms['linkDummyForm'].onsubmit();}document.forms['linkDummyForm'].submit();return false;" id="tree_node_5"><img src="/Test/faces/myFacesExtensionResource/tree.HtmlTree/11266487/images/node_open.gif" border="0" /></a></td><td><img src="/Test/faces/myFacesExtensionResource/tree.HtmlTree/11266487/images/folder.gif" border="0" /></td><td colspan="2" class="treenode"><a href="#" onclick="clear_linkDummyForm();document.forms['linkDummyForm'].elements['linkDummyForm:_link_hidden_'].value='tree_node_0';if(document.forms['linkDummyForm'].onsubmit){document.forms['linkDummyForm'].onsubmit();}document.forms['linkDummyForm'].submit();return false;" id="tree_node_0">parent</a></td></tr>
  5. <tr><td><img src="/Test/faces/myFacesExtensionResource/tree.HtmlTree/11266487/images/noline.gif" border="0" /></td><td><img src="/Test/faces/myFacesExtensionResource/tree.HtmlTree/11266487/images/line_middle.gif" border="0" /></td><td colspan="2" class="treenode"><a href="#" onclick="clear_linkDummyForm();document.forms['linkDummyForm'].elements['linkDummyForm:_link_hidden_'].value='tree_node_1';if(document.forms['linkDummyForm'].onsubmit){document.forms['linkDummyForm'].onsubmit();}document.forms['linkDummyForm'].submit();return false;" id="tree_node_1">A</a></td></tr>
  6. <tr><td><img src="/Test/faces/myFacesExtensionResource/tree.HtmlTree/11266487/images/noline.gif" border="0" /></td><td><img src="/Test/faces/myFacesExtensionResource/tree.HtmlTree/11266487/images/line_middle.gif" border="0" /></td><td colspan="2" class="treenode"><a href="#" onclick="clear_linkDummyForm();document.forms['linkDummyForm'].elements['linkDummyForm:_link_hidden_'].value='tree_node_2';if(document.forms['linkDummyForm'].onsubmit){document.forms['linkDummyForm'].onsubmit();}document.forms['linkDummyForm'].submit();return false;" id="tree_node_2">B</a></td></tr>
  7. <tr><td><img src="/Test/faces/myFacesExtensionResource/tree.HtmlTree/11266487/images/noline.gif" border="0" /></td><td><img src="/Test/faces/myFacesExtensionResource/tree.HtmlTree/11266487/images/line_middle.gif" border="0" /></td><td colspan="2" class="treenode"><a href="#" onclick="clear_linkDummyForm();document.forms['linkDummyForm'].elements['linkDummyForm:_link_hidden_'].value='tree_node_3';if(document.forms['linkDummyForm'].onsubmit){document.forms['linkDummyForm'].onsubmit();}document.forms['linkDummyForm'].submit();return false;" id="tree_node_3">A</a></td></tr>
  8. <tr><td><img src="/Test/faces/myFacesExtensionResource/tree.HtmlTree/11266487/images/noline.gif" border="0" /></td><td><img src="/Test/faces/myFacesExtensionResource/tree.HtmlTree/11266487/images/line_last.gif" border="0" /></td><td colspan="2" class="treenode"><a href="#" onclick="clear_linkDummyForm();document.forms['linkDummyForm'].elements['linkDummyForm:_link_hidden_'].value='tree_node_4';if(document.forms['linkDummyForm'].onsubmit){document.forms['linkDummyForm'].onsubmit();}document.forms['linkDummyForm'].submit();return false;" id="tree_node_4">D</a></td></tr></table>
  9. <form id="linkDummyForm" name="linkDummyForm" style="display:inline" method="post" action="/Test/faces/tree.jsp"><input type="hidden" name="linkDummyForm:_link_hidden_" /><script type="text/javascript"><!--
  10. function clear_linkDummyForm() {
  11.   var f = document.forms['linkDummyForm'];
  12.   f.elements['linkDummyForm:_link_hidden_'].value='';
  13.   f.target='';
  14. }
  15. clear_linkDummyForm();
  16. --></script></form>
  17. </body>
  18. </html>


Et il ne trouve aucune des images qu'il doit afficher (elles sont bien dans le Jar de tomahawk) telles que "/Test/faces/myFacesExtensionResource/tree.HtmlTree/11266487/images/folder.gif" par exemple.
 
PS : mon projet s'appelle Test
 
merci.


---------------
J.C. Farinet
Reply

Marsh Posté le 10-03-2006 à 15:31:52   

Reply

Marsh Posté le 26-06-2006 à 13:58:28    

J'ai un petit souci avec le tree2 de Tomahawk.
 
Ma page tree.jsp.

Code :
  1. <%@ page session="true" contentType="text/html;charset=utf-8" %>
  2. <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
  3. <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
  4. <%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %>
  5. <html>
  6. <%@ include file="inc/head.inc" %>
  7. <body>
  8. <f:view>
  9.     <t:tree2 id="clientTree" value="#{treeBacker.treeModel}" var="node" varNodeToggler="t" preserveToggle="false" clientSideToggle="false">
  10.     <f:facet name="foo-folder">
  11.             <h:panelGroup>
  12.                 <f:facet name="expand">
  13.                     <t:graphicImage value="images/yellow-folder-open.png" rendered="#{t.nodeExpanded}" border="0"/>
  14.                 </f:facet>
  15.                 <f:facet name="collapse">
  16.                     <t:graphicImage value="images/yellow-folder-closed.png" rendered="#{!t.nodeExpanded}" border="0"/>
  17.                 </f:facet>
  18.                 <h:outputText value="#{node.description}" styleClass="nodeFolder"/>
  19.                 <h:outputText value=" (#{node.childCount})" styleClass="childCount" rendered="#{!empty node.children}"/>
  20.             </h:panelGroup>
  21.         </f:facet>
  22.          <f:facet name="class-node">
  23.             <h:panelGroup>
  24.                 <f:facet name="expand">
  25.                     <t:graphicImage value="images/yellow-folder-open.png" rendered="#{t.nodeExpanded}" border="0"/>
  26.                 </f:facet>
  27.                 <f:facet name="collapse">
  28.                     <t:graphicImage value="images/yellow-folder-closed.png" rendered="#{!t.nodeExpanded}" border="0"/>
  29.                 </f:facet>
  30.                 <h:outputText value="#{node.description}" styleClass="nodeFolder"/>
  31.             </h:panelGroup>
  32.         </f:facet>
  33.         <f:facet name="product-node">
  34.             <h:panelGroup>
  35.                 <f:facet name="expand">
  36.                     <t:graphicImage value="images/blue-folder-open.gif" rendered="#{t.nodeExpanded}" border="0"/>
  37.                 </f:facet>
  38.                 <f:facet name="collapse">
  39.                     <t:graphicImage value="images/blue-folder-closed.png" rendered="#{!t.nodeExpanded}" border="0"/>
  40.                 </f:facet>
  41.                 <h:outputText value="#{node.description}" styleClass="nodeFolder"/>
  42.                 <h:outputText value=" (#{node.childCount})" styleClass="childCount" rendered="#{!empty node.children}"/>
  43.             </h:panelGroup>
  44.         </f:facet>
  45.     </t:tree2>
  46. </f:view>
  47. </html>


 
Mon treeBacker (le java bean).

Code :
  1. public class TreeBacker {
  2. private TreeModelBase treeModel;
  3. //private JSFRequestManager jsfRM;
  4. public TreeBacker() {
  5.  //TreeNode treeData = this.jsfRM.getTreeData();
  6.  //TreeNode treeData = this.makeTree();
  7.  treeModel = new TreeModelBase(this.makeTree());
  8. }
  9. public TreeModel getTreeModel() {
  10.  return treeModel;
  11. }
  12. @SuppressWarnings("unchecked" )
  13. public TreeNode makeTree() {
  14.  //return null;
  15.  TreeNode treeData = new TreeNodeBase("foo-folder", "Results", false);
  16.  TreeNodeBase classNode = new TreeNodeBase("class-node", "class-name-from-DB", false);
  17.  TreeNodeBase productNode = new TreeNodeBase("product-node", "product-reference-from-DB", false);
  18.  classNode.getChildren().add(productNode);
  19.  treeData.getChildren().add(classNode);
  20.  return treeData;
  21. }
  22. }


J'essaye de faire ca le plus simple possible pour voir d'où vient mon problème.
 
Et dans mon projet-config.xml j'ai.

Code :
  1. <managed-bean>
  2.  <managed-bean-name>treeBacker</managed-bean-name>
  3.  <managed-bean-class>beans.TreeBacker</managed-bean-class>
  4.  <managed-bean-scope>session</managed-bean-scope>
  5. </managed-bean>


 
Résultat quand j'accéde à ma page tree.jsp.

Code :
  1. HTTP Status 500 -
  2. type Exception report
  3. message
  4. description The server encountered an internal error () that prevented it from fulfilling this request.
  5. exception
  6. org.apache.jasper.JasperException: Exception in JSP: /tree.jsp:9
  7. 6: <html>
  8. 7: <%@ include file="inc/head.inc" %>
  9. 8: <body>
  10. 9: <f:view>
  11. 10:     <t:tree2 id="clientTree" value="#{treeBacker.treeModel}" var="node" varNodeToggler="t" preserveToggle="false" clientSideToggle="false">
  12. 11:     <f:facet name="foo-folder">
  13. 12:             <h:panelGroup>
  14. Stacktrace:
  15. org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
  16. org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
  17. org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  18. org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  19. javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  20. root cause
  21. java.lang.NullPointerException
  22. javax.faces.webapp.UIComponentTag.setupResponseWriter(UIComponentTag.java:929)
  23. javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:310)
  24. org.apache.myfaces.taglib.core.ViewTag.doStartTag(ViewTag.java:70)
  25. org.apache.jsp.tree_jsp._jspx_meth_f_view_0(tree_jsp.java:112)
  26. org.apache.jsp.tree_jsp._jspService(tree_jsp.java:88)
  27. org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
  28. javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  29. org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
  30. org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  31. org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  32. javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  33. note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
  34. Apache Tomcat/5.5.17


 
Je ne comprends pas d'où vient le problème. Ai-je oublié des choses dans les fichiers de config ou bien?


Message édité par sirthomaslipton le 26-06-2006 à 13:59:27

---------------
Stockholm -- guides privés -- vélotaf à Stockholm
Reply

Marsh Posté le 27-06-2006 à 16:06:17    

Ok, j'ai résolu le problème. MP si ca intéresse quelqu'un.


---------------
Stockholm -- guides privés -- vélotaf à Stockholm
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed