Ajax update has no effect, Firefox errors: XML or text ad is not at the beginning of the object

I have a small form that will receive values ​​from a class. However, clicking the button will not update selectOneMenu.

Updating the form will correctly populate the menu with the correct elements.

I expected

update="instrument"/>

to refresh the contents of the menu. But I think I'm missing something. Note that the method in the bean is called when the button is clicked. The list is populated, and int is set when an item is selected.

<h:form id="listForm">

            <p:outputLabel for="instrument" value="Instrument " />
            <p:selectOneMenu id="instrument" value="#{tradeFactory.intInstrumentID}" style="width:150px">
                <p:ajax listener="#{tradeFactory.onInstrumentChange(tradeFactory.intInstrumentID)}" update="instrument" />
                <f:selectItem itemLabel="Select Instrument" itemValue="" noSelectionOption="true" />
                <f:selectItems value="#{tradeFactory.instrumentID}" />
            </p:selectOneMenu>
            <p:commandButton value="Update" actionListener="#{tradeFactory.getInstrumentIDs()}" update="instrument"/>

Update function

@PostConstruct
public void getInstrumentIDs() {
    Set<Integer> s = trades.keySet();

    instrumentID.clear();

    s.stream().forEach(i -> instrumentID.put(String.valueOf(i), String.valueOf(i)));
}

Ajax response body

<?xml version='1.0' encoding='UTF-8'?>
<?xml version='1.0' encoding='UTF-8'?>
<partial-response id="j_id1"><changes><update id="growl"><![CDATA[<span id="growl"></span><script id="growl_s" type="text/javascript">$(function(){PrimeFaces.cw('Growl','widget_growl',{id:'growl',sticky:false,life:5000,escape:true,msgs:[]});});</script>]]></update><update id="listForm:instrument"><![CDATA[<div id="listForm:instrument" class="ui-selectonemenu ui-widget ui-state-default ui-corner-all" style="width:150px"><div class="ui-helper-hidden-accessible"><input id="listForm:instrument_focus" name="listForm:instrument_focus" type="text" autocomplete="off" /></div><div class="ui-helper-hidden-accessible"><select id="listForm:instrument_input" name="listForm:instrument_input" tabindex="-1" onchange="PrimeFaces.ab({s:&quot;listForm:instrument&quot;,e:&quot;valueChange&quot;,f:&quot;listForm&quot;,p:&quot;listForm:instrument&quot;,u:&quot;listForm:instrument&quot;});"><option value="">Select Instrument</option><option value="101" selected="selected">101</option></select></div><label id="listForm:instrument_label" class="ui-selectonemenu-label ui-inputfield ui-corner-all">&nbsp;</label><div class="ui-selectonemenu-trigger ui-state-default ui-corner-right"><span class="ui-icon ui-icon-triangle-1-s ui-c"></span></div><div id="listForm:instrument_panel" class="ui-selectonemenu-panel ui-widget-content ui-corner-all ui-helper-hidden ui-shadow"><div class="ui-selectonemenu-items-wrapper" style="height:auto"><ul class="ui-selectonemenu-items ui-selectonemenu-list ui-widget-content ui-widget ui-corner-all ui-helper-reset"><li class="ui-selectonemenu-item ui-selectonemenu-list-item ui-corner-all" data-label="Select Instrument">Select Instrument</li><li class="ui-selectonemenu-item ui-selectonemenu-list-item ui-corner-all" data-label="101">101</li></ul></div></div></div><script id="listForm:instrument_s" type="text/javascript">$(function(){PrimeFaces.cw("SelectOneMenu","widget_listForm_instrument",{id:"listForm:instrument",widgetVar:"widget_listForm_instrument",behaviors:{valueChange:function(ext) {PrimeFaces.ab({s:"listForm:instrument",e:"valueChange",f:"listForm",p:"listForm:instrument",u:"listForm:instrument"},ext);}}});});</script>]]></update><update id="j_id1:javax.faces.ViewState:0"><![CDATA[6pU4fJ833iSGEfN+jgq6Xf7Cm9bY1/D+lP5rGqXRcyk7Iny5mlcxgMIwtSzAH+wmsNVWqKhQSOW+daWL0ldPSks95pfT4GtmvNE6/0Wlnb4X4379LlfKxTNV9jfRbQxcoVpc+DUYCZwPXvF1ewWdv/lm5KlYlqKjtq8M1YKow1bCObQjfE/UjnTOVisLhJec1I2c0vQPGen58TTJ2xRacq8BYx+Flanxtl8uiiySVVNP+AJaxIym3qSV3tegWXLTTNPNqIAt46Iq1y8NmueLOmgYhkJai3Xc0VLRIaALakjPO3GruPvz16TUVmYXejcsJb9bieuDsh94a6gc+FK6oP/h0zBZ/WDf8wwD9MDlXccfIDwlqFOGyAOjjvVBW/FjtoiIyaMMnlDHeohWYoRGxYdU6Nk1A5sY/sIqJclVgmoqgqmlEqzg2aGji/87w77ewL4mniQYlLDEsh0yMP/XMp7eYfBKMJz/+wjOHIEvy/mlej42rNoNy/DxtgX/2vJmUlWroVK01LIEpKVfHgFyCA1qA001dylXeiGka7WENoqyW4ocPY4/kbFEbbbnPt8O+rJlbC735WQGoZsriHAtJe9cOxKaQ2Ca9x8ISeqgEoVAGRxynDtwVp2EsIOTsBczHvHn7VDmlhEHxSbGq6wmnUPMOHL4TitGt3q3708UL/S5TRmLmHJEFJ1zqhdUJ5KqhkKqyrspU3CqFkKAw8nsrRlZSc9m4Yj3vsiDzTMFnTx4EnF+p227QeKsUbor+AO/7+qbX3yXvWNDsifEoz+gNK5eGp7aWm0jJEHsrdbCsE8pg6AtfO0Cua3lvGIHL1o6ApQqMZtNyPJcYHO3a9giD68m2gfvhXm/XeGubocuP+GlVxViOouHHAnl7ur5ufDU3GYEGd9iIoIt4fLXDblIwoL4rFLRCGHp3eLW2UBDEVcZ+2rQAy0m3CcIMtzUhSHaEub7wEmaKO+gacp1bpygFxSFj0umQFafRbbNuvoU1rhTib+z+xwxwMP+XbYOqp+K0HUFBxMuoymn07KDn1kOzJsvG32CoDyQJ5advznRsg1wWaLz8NJsEMOz/AbPj+eV5Y5b+76mH5VVANpOibTJ2QQYnzl0bR8PdApngOCBQ9pjJoIZ3HTQ5MehorVHK1o58RV0Y88zLzYIeljJWURy8bBIBpKsX6BxZr5noQlxogPtZ47IWy+6tiLqgyfvT8/aAsxOtAtCAgdXQO8y0rv5fI/6M3QfX+slTuDQAUOjYIi+Z0q6SZdwWpVJn43LB7PucRt73nP6T34RUwekzc351O9/IP+XI+bizxoQFGrBVmY=]]></update></changes></partial-response>

Firefox console

15:18:52.737 XML or text declaration not at start of entity1 trades.xhtml:2:1

Maven pom

<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <version>2.9</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-json-jackson</artifactId>
    <version>2.9</version>
</dependency>
<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.3.1</version>
</dependency>
<dependency>
    <groupId>joda-time</groupId>
    <artifactId>joda-time</artifactId>
    <version>2.6</version>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>
<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-api</artifactId>
    <version>2.2.10</version>
</dependency>
<dependency>
    <groupId>org.primefaces</groupId>
    <artifactId>primefaces</artifactId>
    <version>5.2</version>
</dependency>
+1
source share
1 answer

Ajax update error caused by double XML prolog in ajax response:

<?xml version='1.0' encoding='UTF-8'?>
<?xml version='1.0' encoding='UTF-8'?>

Can be only one.

/ JSF API . , / API impl.

, Maven barebones servletcontainer (Tomcat) , Mojarra (2.2.11) javax.faces.jar, :

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.faces</artifactId>
    <version>2.2.11</version>
</dependency>

, jsf-api jsf-impl.

+2

Source: https://habr.com/ru/post/1686615/


All Articles