vendredi 11 septembre 2015

JQuery Autocomplete function- Selected value doesn't get available in the spring bean class

I am working on replacing a large dropdown ( which makes a performance impact due t browser rendering) with a Jquery autocomplete input box. I can get the autocomplete functionality to work however the selected value doesn't get available in the java bean class. Here my code

<script>

var productionSourceListString =      document.getElementById("hiddenField").value;
var productionSourceListArray = productionSourceListString.split(',');
$(document).ready(function(){
$("#centerForm\\:production_source").autocomplete({ source :  productionSourceListArray, minLength: 3 });   
$( "#centerForm\\:production_source" ).on( "autocompletechange", function()  {$( "#centerForm\\:production_source" ).attr("value",this.value);} );

});
</script>
<h:inputText  id="production_source" style="width:80px; overflow:hidden"   value="#{recurringSplitBean.item.productionSource.description}">
</h:inputText>

<input type="hidden" id="hiddenField" value="#{productionSourceBean.productionSourceList}"/>

Spring Bean Class(To get the list of elements in dropdown and store them in a comma delimited string declared globally)

private String productionSourceList = ""; (GLOBAL)

public void getProductionSourceListAjax(AjaxBehaviorEvent event){

    List<String> localList = new ArrayList<String>();
    Iterator<ProductionSource> iterator = this.getLovItems().iterator();

    while(iterator.hasNext())
    {
        localList.add(iterator.next().getDescription());
    }

    productionSourceList = StringUtils.collectionToCommaDelimitedString(localList);     
}

When I try to access the value in RecurringSplitBean class

if(AppSupport.isEmpty(item.getProductionSource()) || AppSupport.isEmpty(item.getProductionSource().getProductionSourceId())){           
        JsfMessage.addError("production_source","error.value.required");
        return null;
    }

item.getProductionSource().getDescription() is null. However rather than selecting a value from the list provided by the Jquery dropdown if I type a value in the input box the value becomes available in the recurringsplitbean class. Any thoughts ? :)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire