Bootsfaces inputText loses focus caused by using ajax value and update in bean

I found a problem when using bootsfaces inputText with ajax. I am using JSF 2.2, Bootsfaces 0.8.1 and Primefaces 5.3.

I am trying to enter a date value in the inputText field. As soon as I enter the last value for the date, inputText should raise a change event. At this point, I would like to use ajax to call the bean method. The problem is that my field loses focus as soon as I try to enter the last value, and the method has never been called.

So, I did a little work with Primefaces, and it works almost the way I wanted. At this stage, I had different questions:

  • Why does inputText lose focus when I enter the last value? ( Bootsfaces )
  • Why was the bean method never called after I lost focus? ( Bootsfaces )
  • Is it possible to call the bean method after the bean value has been set by this field? ( Primefaces )

I have added the code below, so maybe you can reproduce this behavior.

test.xhtml - an xhtml example with fields with both primary and boot surfaces

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:b="http://bootsfaces.net/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <h:head>
        <meta charset="UTF-8"/>
    </h:head>

    <h:body>
        <h:form id="form">
            <b:panel id="filterPanel" title="Filter properties" immediate="true" collapsed="false" collapsible="true">
                <b:row>
                    <b:column span="12">
                        <b:inputText id="dateA" type="date" value="#{test.dateA}" immediate="true" class="form-control">
                            <f:ajax event="change" listener="#{test.searchA()}"/>
                        </b:inputText>
                    </b:column>
                </b:row>
                <b:row>
                    <b:column span="12">
                        <p:inputText id="dateB" type="date" value="#{test.dateB}" immediate="true" class="form-control">
                            <p:ajax event="change" listener="#{test.searchB()}"/>
                        </p:inputText>
                    </b:column>
                </b:row>
            </b:panel>
        </h:form>
    </h:body>
</html>

TestBean.java - my bean for setting values ​​and calling methods

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

@ManagedBean(name = "test")
@ViewScoped
public class TestBean {

    private String dateA;
    private String dateB;

    public void searchA() {
        System.out.println("Search A");
    }

    public void searchB() {
        System.out.println("Search B");
    }

    public String getDateA() {
        return dateA;
    }

    public void setDateA(String dateA) {
        this.dateA = dateA;
        System.out.println(dateA);
    }

    public String getDateB() {
        return dateB;
    }

    public void setDateB(String dateB) {
        this.dateB = dateB;
        System.out.println(dateB);
    }

}

Please help me find a solution or explain what I'm doing wrong here.

Thanks MWeber

+4
source share
1 answer

BootsFaces PrimeFaces. process update .

    <b:inputText id="dateA" type="date" value="#{test.dateA}" immediate="true" class="form-control">
        <f:ajax event="change" listener="#{test.searchA()}" render="@none"/>
    </b:inputText>

BootsFaces , PrimeFaces.

update process . BootsFaces 0.8.5, :

  • process = "@form" <b:commandButton /> <b:commandLink />
  • process = "@this" BootsFaces
  • update = "@form" BootsFaces

/ PrimeFaces JSF f: ajax execute/render, PrimeFaces : enter image description here

XHTML:       
      http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "                   XMLNS: =" http://bootsfaces.net/ui "
            XMLNS: =" http://java.sun.com/jsf/html "
            XMLNS: =" http://java.sun.com/jsf/core "
            xmlns: p =" http://primefaces.org/ui" >

        <h:head>                                                                                                            
            <meta charset="UTF-8"/>                                                                                         
        </h:head>                                                                                                           

        <h:body>                                                                                                            
            <h:form id="form">                                                                                              
                <b:panel id="filterPanel" title="Filter properties" immediate="true" collapsed="false" collapsible="true">  
                    <b:row>                                                                                                 
                        <b:column span="12">                                                                                
                            <b:inputText id="dateA" type="date" value="#{test.dateA}" immediate="true" class="form-control">
                                <f:ajax event="change" listener="#{test.searchA()}" render="@none"/>                        
                            </b:inputText>                                                                                  
                        </b:column>                                                                                         
                    </b:row>                                                                                                
                    <b:row>                                                                                                 
                        <b:column span="12">                                                                                
                            <p:inputText id="dateB" type="date" value="#{test.dateB}" immediate="true" class="form-control">
                                <p:ajax event="change" listener="#{test.searchB()}"/>                                       
                            </p:inputText>                                                                                  
                        </b:column>                                                                                         
                    </b:row>                                                                                                
                </b:panel>                                                                                                  
            </h:form>                                                                                                       
        </h:body>                                                                                                           
    </html>                                                                                                                 

BootsFaces 0.8.5.

+2

All Articles