2016-04-06 20 views
0

當觸發此事件(onkeyup)時,adminiEvent bean上不會調用searchClients方法。Boots在不調用服務器bean的輸入文本上觸發ajax事件

<b:inputText placeholder="nome" required="true" id="name" 
       value="#{adminiEvent.clientOnSearch.firstName}" 
       onkeyup="#{adminiEvent.searchingClients}"  update=":adminiForm:clientSearchTable" 
       style="background: rgb(251, 251, 251) none repeat scroll 0% 0%; 
        box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);" 
        /> 

有什麼想法嗎?

這裏的豆:

@ManagedBean(name="adminiEvent" , eager=true) 
@ViewScoped 
public class AdminiEvent { 
... 
public void searchingClients(){ 
    List<Client> values = new ArrayList<Client>(); 
    //build query 
    Map<String,Object> queryValues = new HashMap<String,Object>(); 
    StringBuilder query = new StringBuilder(); 

    query.append("Select c from Client c where "); 

    if(!StringUtils.isEmpty(clientOnSearch.getFirstName())){ 
     query.append("c.firstName = :firstname"); 
     queryValues.put("firstname", clientOnSearch.getFirstName()); 
    } 

    if(!queryValues.isEmpty()){ 
     values.addAll(clientService.findClientByFilter(query.toString(),queryValues)); 
    } 

    clients.addAll(values); 
    } 
... 

感謝

這裏多試驗幾次我提出:

onkeyup="alert('test');ajax:adminiEvent.searchingClients;javascript:alert('test 2');" 
value="#{adminiEvent.clientOnSearch.firstName}" 
style="background: rgb(251, 251, 251) none repeat scroll 0% 0%; 
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);"/>` 

它運行良好的第一和第二警報,但searchingClients不叫。我在服務器端的調試模式,我什麼都沒有。瀏覽器調試控制檯或服務器控制檯上也沒有顯示任何內容。

擷取畫面的HTML生成:

enter image description here

感謝

回答

1

首先,你發現在BootsFaces 0.8.1的錯誤。它應該在BootsFaces的開發者快照中修復 - 請參閱https://github.com/TheCoder4eu/BootsFaces-OSP/issues/151瞭解如何獲取它。

其次,您已嘗試調用JavaScript方法。要將其變爲後端bean調用,您必須在它之前加上「ajax:」並移除大括號。另外,您必須添加Java方法的括號。最後,重要的是,這種方法必須存在。 JSF有時會自動添加一個前綴,如「get」,「set」或「is」。 BootsFaces不會。因此,您的示例應如下所示:

<b:inputText onkeyup="ajax:adminiEvent.getSearchingClients()" ... /> 

閱讀完整故事http://showcase.bootsfaces.net/forms/ajax.jsf。您可能還對https://github.com/stephanrauh/BootsFaces-Examples/tree/master/AJAX的示例感興趣。

順便說一句,我修復了BootsFaces 0.8.2-SNAPSHOT中的錯誤。 0.9.0-SNAPSHOT目前比0.8.2-SNAPSHOT早,因爲我們已經開始修復大量的錯誤而不是添加新的功能。

我測試過BootsFaces 0.8.2-SNAPSHOT這兩個文件:

<?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:b="http://bootsfaces.net/ui"                                   
      xmlns:ui="http://java.sun.com/jsf/facelets"                                 
      xmlns:pt="http://xmlns.jcp.org/jsf/passthrough" >                               
     <h:head>                                          
      <title>BootsFaces: next-gen JSF Framework</title>                               
      <meta name="author" content="Riccardo Massera"></meta>                             
     </h:head>                                          
     <h:body style="padding-top: 60px">                                   
     <h:form>                                          
     lorem ipsum                                         
     <b:inputText placeholder="nome" required="true" id="name"                              
        onkeyup="ajax:adminiEvent.searchingClients()"                              
        onclick="ajax:adminiEvent.searchingClients()"                              
        update="@none"                                     
         />                                       
     </h:form>                                          
     </h:body>                                          
    </html>                                           

import javax.faces.bean.ManagedBean;                                    
    import javax.faces.view.ViewScoped;                                    

    @ManagedBean                                          
    @ViewScoped                                          
    public class AdminiEvent {                                      
     private String firstName;                                      

     public void searchingClients() {                                    
      System.out.println("Backend bean called: " + firstName);                             
     }                                            

     public String getFirstName() {                                    
      return firstName;                                       
     }                                            

     public void setFirstName(String search) {                                  
      this.firstName = search;                                     
     }                                            
    } 
+0

感謝斯蒂芬,但遺憾的是不工作也喜歡。因此,我在這裏做了以下修改:onkeyup =「ajax:adminiEvent.searchingClients」on the final html code:onkeyup =「; BsF.ajax.callAjax(this,event,'adminiForm:clientSearchTable','adminiForm:name',null,'更改');然後我更改了服務器方法:public String searchingClients(){....}如果我添加alert('test'); onkeyup,則會觸發該警報 –

+0

我也將其更改爲:onkeyup =「ajax :adminiEvent.searchingClients()「但是沒有任何事發生 –

+0

OK,剛剛看到你的bean沒有一個searchClients()方法,你必須使用方法的真實名稱和簽名,在你的情況下,應該是」ajax :adminiEvent.getSearchingClients()「。 –

相關問題