使用jsf开发一个网页,
想在网页上实现一个功能:比如有一个按钮,每当我按一下这个按钮,就会在网页上添加一个jsf的组件,并且添加这个组件时页面不刷新
请问这个用ajax怎么实现?这个网页对应的backingbean怎么处理新添加的这个组件?呃不要用太多的js最好是什么组件化些的。。有没有这方面的教程或是文档?
实现这个,用jsf用2.0会不会比1.2简单些?ps:java web开发和java ee这两个板块定位有什么区别

解决方案 »

  1.   

    使用ajax4jsf的a4j:commandButton组件,在组件的action中,动态创建组件
    比如创建一个h:inputText组件 HtmlInputText input = FacesContext.getCurrentInstance().getAppliaction().createComponent(HtmlInputText.COMPONENT_TYPE);
      

  2.   

    使用ajax4jsf的a4j:commandButton组件,在组件的action中,动态创建组件
    比如创建一个h:inputText组件 HtmlInputText input = FacesContext.getCurrentInstance().getAppliaction().createComponent(HtmlInputText.COMPONENT_TYPE);
      

  3.   

    十分感谢,这个应该可以
    不过我还不大明白具体的,能说的详细些么
    .jsp文件应该怎么写
    <a4f:commandButton action="#{backingbean.addcomponents}"/>
    backingbean.javaHtmlInputText input= FacesContext.getCurrentInstance().getAppliaction().createComponent(HtmlInputText.COMPONENT_TYPE);
    backingbean中这样写么?在backingbean中add出的jsf组件对应的变量在哪里?
      

  4.   

    十分感谢,这个应该可以 
    不过我还不大明白具体的,能说的详细些么 
    .jsp文件应该怎么写 
    <a4f:commandButton action="#{backingbean.input}"/
    backingbean.java HtmlInputText input= FacesContext.getCurrentInstance().getAppliaction().createComponent(HtmlInputText.COMPONENT_TYPE); 
    backingbean中这样写么?在backingbean中add出的jsf组件对应的变量在哪里?
      

  5.   

    假如添加到组件表格<h:panelGrid id="grid1">中,只需要在动态添加组件后,重新渲染grid1,
    在a4j:commandButton组件中就是使用reRender属性(reRender="grid1"),这样就不会刷新整个页面具体代码:
    <%@taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
    <f:view>
       <h:form  id="form1">
        <h:panelGrid id="grid1">
        </panelGrid>
         <a4j:commandButton value="动态添加组件" 
                     action="#{backingbean.addComponentAction}"  reRender="grid1">
       </h:form>
    </f:view>
    backingbean public String addComponentAction(){   /**
        *拿到组件树的根节点,然后对其遍历,找到id=grid1的组件h:panelGrid
        */
       HtmlPanelGrid grid1 = null;   UIViewRoot  viewRoot =FacesContext.getCurrentInstance().getViewRoot();   Iterator kids = viewRoot.getFacetsAndChildren();
       while(kids.hasNext()){
          UIComponent kid =(UIComponent) kids.next();
          if("gird1".equals(kid.getId()){
            gird1=(HtmlPanelGrid)kid ;
            break;
          }
          
       }
     /**
      * 创建一个h:inputText组件
      */
      HtmlInputText input = FacesContext.getCurrentInstance().getAppliaction().createComponent(HtmlInputText.COMPONENT_TYPE);
       
       input.setId("input1");
       grid1.getChildren().add(input);//添加到grid中
       return null;
     
     }这样就不需要刷新整个页面,只是局部刷新H:panelGrid组件大致是这样的,代码是我在这里面直接敲得,肯定有错误的地方,估计问题不大怎么引入ajax4jsf,配置web.xml,网上很多,可以找找看
      

  6.   

    看看 金蝶的
     OperaMask的实现...JSF + ExtJS2.2