MyActionListener.java:8: 软件包 javax.faces.tree 不存在
import javax.faces.tree.Tree;已经将 jsf-api.jar 放在jdk 的lib 目录下,也添加到了classpath中,能找到
javax.faces.component.UIComponent
打开jsf-api.jar jsf-ri.jar jsf-impl.jar中都找不到javax.faces.tree.Tree
求高手解答啊 。。这是我的第一个JSF例子。。代码。。
package ch01a;import java.util.Iterator;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;
import javax.faces.tree.Tree;public class MyActionListener
{
public PhaseId getPhaseId(){
System.out.println("getPhaseId called..");
return PhaseId.APPLY_REQUEST_VALUES;
}public void processAction(ActionEvent event){
System.out.println("processAction called");
//the componet that trigegered the action event
UIComponent component =event.getComponent();
System.out.println(
"The id of the component that fired the action event:"
+component.getComponentId());
//the action command
String actionCommand=event.getActionCommand();
System.out.println("Action command :"+actionCommand);FacesContext facesContext=FacesContext.getCurrentInstance();
Tree tree=facesContext.getTree();
UIComponent root=tree.getRoot();
System.out.println("---------Component Tree------------");
navigateComponentTree(root,0);
System.out.println("-----------------------------------");
}private void navigateComponentTree(UIComponent root,int level){
//indent
for(int i=0;i<level;i++){
System.out.print(" ");
//print component id
System.out.println(component.getComponentId());
Iterator children=component.getChildren();
//navigate children
while(children.hasNext){
UIComponent child=(UIComponent)children.next();
navigateComponentTree(child,level+1);
}
}}
}

解决方案 »

  1.   

    我的JAVAHOME=D:\software\Java\jdk1.6.0_10,
    我把要用的.jar包放在这里,
    D:\software\Java\jdk1.6.0_10\jre\lib\ext
    同时,我还有.dll放在这里,
    D:\software\Java\jdk1.6.0_10\jre\bin
    楼主根据自己的JAVAHOME路径,相应变换,JAVAHOME是JDK路径,不是JRE的。
    最后,楼主成功后,一定要结贴给分啊。
      

  2.   

    不是环境变量的问题,,是JAR包的问题。。她提供的JAR里没有那个,javax.faces.*里没有tree.Tree
    不知怎么回事
      

  3.   

    我说的不是环境变量。是告诉你,.jar
    “已经将 jsf-api.jar 放在jdk 的lib 目录下,也添加到了classpath中,能找到”放这里不对!
    .jar要放我上面说的地方。
      

  4.   

    ..那个JAR包我打开看了没有TREE那个CLASS
    你的 jsf-api.jar 里有javax.faces.tree.Tree这个class吗? 有的话求共享import javax.faces.component.UIComponent;
    import javax.faces.context.FacesContext;
    import javax.faces.event.ActionEvent;
    import javax.faces.event.ActionListener;
    import javax.faces.tree.Tree;
    前四个都找到了,就是最后一个里面没有
      

  5.   

    话说你从哪里听说有个tree啊?如果是下的某个sample,就从那个网站找找呗。应该是某个插件提供的
      

  6.   

    我找的书上的例子。有TREE呢。好几个例子都用呢。。
    不会是我的书是2005的太早了吗?
      

  7.   

    你的.jar是好像不是标准包里的啊,也可能是过时了,换地方了
    import javax.faces.component.UIComponent;
    import javax.faces.context.FacesContext;
    import javax.faces.event.ActionEvent;
    import javax.faces.event.ActionListener;
    import javax.faces.tree.Tree;
    这些没有一个我在1.6jdk理找得到的。你前几个都在哪找到的呢?最后一个应该也在那里
      

  8.   

    ..jsf-api。jar里找的啊 不在jdk里
      

  9.   

    书上的例子。。不是下载的 。。你对JSF有了解吗?、这个东西您曾经见过吗?
      

  10.   

    实在抱歉啊,没什么研究。那你看看书上前言之类的,有没有说什么书上要用到的一些.jar在哪里下载。很多书,在一开始都会写的。也可能在光盘里面。
      

  11.   

    。。恩 谢谢了。。麻烦了。。期待一个会JSF的高手指点啊