0

When this event (onkeyup) is triggered, the method searchingClients is not called on the adminiEvent bean.

<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);"
                    />

any idea ?

Here's the bean:

@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);
   }
...

Thanks

Here few more tests I made:

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);"/>`

It runs well the first and second alert, but the searchingClients is not called. I am on debug mode in server side and I got nothing there. Also there is nothing displayed on the browser debug console or on the server console.

sreenshot of the html generated:

enter image description here

Thanks

b.lopes
  • 435
  • 1
  • 7
  • 17

1 Answers1

1

First, you've found a bug in BootsFaces 0.8.1. It should be fixed in the developer snapshot of BootsFaces - see https://github.com/TheCoder4eu/BootsFaces-OSP/issues/151 on how to get it.

Second, you've tried to call a JavaScript method. To turn it into a backend bean call, you have to precede it with an "ajax:" and remove the braces. Plus, you have to add the parentheses of a Java method. Last, not least, this method has to exist. JSF sometimes automatically adds a prefix like "get", "set" or "is". BootsFaces does not. So, your example should look like so:

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

Read the full story at http://showcase.bootsfaces.net/forms/ajax.jsf. You might also be interested in the examples at https://github.com/stephanrauh/BootsFaces-Examples/tree/master/AJAX.

BTW, I've fixed the bug in BootsFaces 0.8.2-SNAPSHOT. The 0.9.0-SNAPSHOT is currently older than 0.8.2-SNAPSHOT because we've started to fix a lot of bugs instead of adding new features.

I've tested BootsFaces 0.8.2-SNAPSHOT with these two files:

    <?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>                                                                                                                                                                          

and

    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;                                                                                                                                                 
        }                                                                                                                                                                            
    } 
Stephan Rauh
  • 3,069
  • 2
  • 18
  • 37
  • Thanks Stephan, but unfortunately is not working like that too. So here the changes I made: onkeyup="ajax:adminiEvent.searchingClients" on final html code: onkeyup=";BsF.ajax.callAjax(this, event,'adminiForm:clientSearchTable','adminiForm:name', null, 'change'); then I changed the server method: public String searchingClients(){ ....} If I add alert('test'); onkeyup, the alert is triggered. – b.lopes Apr 09 '16 at 15:41
  • I also changed it to:onkeyup="ajax:adminiEvent.searchingClients()" but nothing happened – b.lopes Apr 09 '16 at 15:51
  • OK, just saw that your bean doesn't have a searchClients() method. You have to use the real name and signature of the method. In your case, that should be "ajax:adminiEvent.getSearchingClients()". – Stephan Rauh Apr 09 '16 at 20:33
  • yes sorry I was modifying it and paste the old code. Now is ok, but not working. I just saw this: [link](http://www.beyondjava.net/blog/an-alternative-api-to-jsf-ajax/) where they say to use **` – b.lopes Apr 09 '16 at 20:50
  • Thanks for pointing out my blog needed an update. Now I've updated it, hoping to avoid confusion in the future. As for your problem: are there any error messages in the JavaScript console, or in the server side log? – Stephan Rauh Apr 09 '16 at 21:31
  • Congratulations! You've found a bug in BootsFaces 0.8.1. I've fixed it and uploaded a developer snapshot to Maven Central. See https://github.com/TheCoder4eu/BootsFaces-OSP/issues/151 on how to get it. Would you mind to test it and confirm the bug has been fixed? – Stephan Rauh Apr 09 '16 at 21:58
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/108724/discussion-between-b-lopes-and-stephan-rauh). – b.lopes Apr 09 '16 at 22:37
  • I have update the original post with more details, but still the server method is not called and nothing is show up on both consoles, browser or server one, and now I am using the bootsfaces 0.9.0-SNAPSHOT – b.lopes Apr 09 '16 at 22:48
  • also check this one [auto-completion-shows-duplicate-properties-style-class-and-stylec](http://stackoverflow.com/questions/36523920/bootsfaces-tag-auto-completion-shows-duplicate-properties-style-class-and-stylec) happened after migrated to bootsfaces 0.9.0-SNAPSHOT – b.lopes Apr 10 '16 at 13:17
  • Your edited version still lacks the parenthesis. It should read `ajax:adminiEvent.searchingClients()` instead of `ajax:adminiEvent.searchingClients`. – Stephan Rauh Apr 10 '16 at 19:31
  • Hi Stephan, still does nothing: `onkeyup="ajax:adminiEvent.searchingClients()` if I put an inside the I can see the searchingClients() being called... but would be better with onkeyup if I could make it work. On your [blog](http://www.beyondjava.net/blog/an-alternative-api-to-jsf-ajax/) you are using it with no () : `onkeyup="console.log('before the AJAX call'); ajax:userBean.onKeyUp; javascript:console.log('after the AJAX call');"` – b.lopes Apr 11 '16 at 18:39
  • any news here ? do you need more details ? Thanks – b.lopes Apr 14 '16 at 18:27
  • I considered your bug solved :). However, my bugfix broke other features of BootsFaces, so we're still working on it. I'll add the working source code to my original answer. Note that the source code depends on BootsFaces 0.8.2, which hasn't been released yet. It doesn't work with BootsFaces 0.8.1. – Stephan Rauh Apr 15 '16 at 21:36
  • and about bootfaces 0.9.0 ? Ok I will switch to 0.8.2 and try it – b.lopes Apr 15 '16 at 22:42
  • Now there is other issue, maybe linked to this fix ? the `value` of the `inputTest` is not returning the value written but the id of the element!! On my bean object firstName property I got this as value `firstName=input_adminiForm:name` instead of the typed value `Bruno` where I am using this `value="#{adminiEvent.clientOnSearch.firstName}"` – b.lopes Apr 15 '16 at 23:01
  • Hi there, do I have to open a new stackoverflow ticket for this issue reported on my previous comment or this is ok here ? – b.lopes Apr 16 '16 at 17:18
  • I've uploaded a new developer snapshot of BootsFaces 0.8.2-SNAPSHOT to Maven Central. The bug you've reported should be fixed by now. In any case, I'm surprised it made it to Maven Central. BTW, if you want to open a new ticket, please open it on our bug tracker (https://github.com/TheCoder4eu/BootsFaces-OSP/issues). Frequently, I receive messages from StackOverflow with one or two days of delay. – Stephan Rauh Apr 16 '16 at 21:31
  • I have this setup on my POM: ` central https://oss.sonatype.org/content/repositories/snapshots true true ` and ` net.bootsfaces bootsfaces 0.8.2-SNAPSHOT compile ` with this version I got that issue. I will try that one form Maven Central. Ok I will go directly to bug Tracker next time! thanks :) – b.lopes Apr 17 '16 at 11:16