2011-12-19 59 views
0

難道有人可以解釋爲什麼a4j:commandButton在第一次點擊下一個場景時沒有反應? 我有兩次擊中它,以獲得執行的操作...爲什麼a4j:commandButton在第一次點擊時沒有反應?

Facelets的複合模板命名principal.xhtml:

 <?xml version="1.0" encoding="UTF-8"?> 
     <!DOCTYPE html> 


     <html xmlns="http://www.w3.org/1999/xhtml" 
       xmlns:h="http://java.sun.com/jsf/html" 
       xmlns:f="http://java.sun.com/jsf/core" 
       xmlns:ui="http://java.sun.com/jsf/facelets" 
       xmlns:a4j="http://richfaces.org/a4j" 
       xmlns:rich="http://richfaces.org/rich"> 


       <f:view contentType="text/html"> 

          <h:head> 
            <meta http-equiv="content-type" content="text/xhtml; charset=UTF-8" /> 
          </h:head> 

          <h:body> 

            <div id="heading"> 
               <ui:insert name="heading"> 
                 <ui:include src="/adm/includes/menu.xhtml"/> 
               </ui:insert> 
            </div> 

            <div id="content"> 
               <br /> 
                 <a4j:outputPanel ajaxRendered="true"> 
                    <ui:insert name="content"/> 
                 </a4j:outputPanel> 
               <br /> 
            </div> 

            <div id="footer"> 
               <ui:insert name="footer"> 
                 <ui:include src="/adm/includes/footer.xhtml"/> 
               </ui:insert> 
            </div> 

          </h:body> 

       </f:view> 
     </html> 

有問題的AJAX按鈕JSF頁面:

   <ui:composition template="/adm/templates/principal.xhtml"> 
          <ui:define name="content"> 
            <rich:panel header="#{msgs.usuariosNuevo}"> 

               <h:form id="formUsuariosNuevo" prependId="false"> 


                 <h:panelGrid columns="3"> 

                    <h:outputText value="#{msgs.email}" /> 
                    <h:inputText value="#{usuarioCtrl.mdl.email}" id="email" /> 

                    <h:outputText value="#{msgs.pwd}" /> 
                    <h:inputSecret value="#{usuarioCtrl.mdl.pwd}" id="pwd" /> 

                 </h:panelGrid> 


                 <a4j:commandButton value="#{msgs.guardar}" action="#{usuarioCtrl.guardarUsuarioAction}" /> 

               </h:form> 

            </rich:panel> 
          </ui:define> 
      </ui:composition> 

...和「頂部」工具欄菜單.xhtml:

<h:form prependId="false" id="formMenu"> 

    <rich:toolbar height="26px">                       

     <rich:dropDownMenu mode="ajax"> 
      <f:facet name="label"> 
       <h:panelGroup> 
        <h:graphicImage value="/resources/img/icon/usuarios.png" styleClass="pic" width="20" height="20" />       
        <h:outputText value="Usuarios" /> 
       </h:panelGroup> 
      </f:facet> 
      <rich:menuItem label="Nuevo" action="#{menuCtrl.usuariosNuevoAction}" icon="/resources/img/icon/nuevo.png" /> 
      <rich:menuItem label="Gestión" action="#{menuCtrl.usuariosGestionAction}" icon="/resources/img/icon/gestion.png" />         
     </rich:dropDownMenu>   

     <!-- Others dropDownsMenu's here ... -->    

    </rich:toolbar> 
</h:form> 

謝謝!

回答

0

我認爲問題發生在使用JSF @ManagedBean時。您需要在當前流中聲明表單bean變量。

我使用RichFaces的4.2,Spring的網絡流量2.3.0,3.1.1春季

的FormBean

@RequestScoped 
@ManagedBean 
public class SearchForm implements Serializable { 
    private static final long serialVersionUID = 1L; 

    private String pattern = "Please insert"; 

    public String getPattern() { 
     return pattern; 
    } 

    public void setPattern(String pattern) { 
     this.pattern = pattern; 
    } 
} 

家庭flow.xml

<var name="searchForm" class="com.inhouse.web.form.SearchForm"/> 

    <view-state id="home" view="home.xhtml" model="searchForm"> 
     <transition on="search"> 
      <evaluate expression="searchController.search(requestParameters.pattern)" result="flashScope.searchResults"></evaluate> 
     </transition> 
</view-state> 

home.xhtml

<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:sf="http://www.springframework.org/tags/faces" 
    xmlns:fn="http://java.sun.com/jsp/jstl/functions" 
    xmlns:a4j="http://richfaces.org/a4j" 
    xmlns:rich="http://richfaces.org/rich"> 
<ui:composition template="/WEB-INF/layouts/template.xhtml"> 
    <ui:define name="content"> 
     <h:form> 
      <h:inputText value="#{searchForm.pattern}" /> 
      <a4j:commandButton action="search" value="Search" render="searchResult" immediate="true"> 
       <f:param name="pattern" value="#{searchForm.pattern}"></f:param> 
      </a4j:commandButton> 
     </h:form> 

     <h:panelGroup id="searchResult"> 
      <h:outputText value="#{searchResults}" /> 
     </h:panelGroup> 
    </ui:define> 
</ui:composition> 
</html> 

控制器

@Controller 
public class SearchController { 
    public String search(String pattern) { 

     return "this is the search results"; 
    } 
} 
+1

對不起,我搬到Primefaces,完全丟棄的情況。 – webmeiker 2012-03-28 10:24:17

+0

好吧,只爲有關的人 – ryan 2012-04-03 06:24:33

相關問題