Ajax更新没有效果,Firefox错误:XML或文本声明不在实体的开头

时间:2015-07-10 12:26:47

标签: jsf primefaces

我有一个小表单,它将从类中接收值。但是,按下按钮不会更新selectOneMenu。

刷新表单将正确填充菜单中正确的项目。

我在期待

update="instrument"/>

刷新菜单内容。但我想我错过了一些东西。请注意,按下按钮时会调用bean中的方法。列表已填充,并且在选择项目时也会设置int。

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

更新功能

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

    instrumentID.clear();

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

Ajax响应正文

<?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控制台

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 个答案:

答案 0 :(得分:3)

ajax更新失败是由ajax响应中的双XML prolog引起的:

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

可能只有一个。

这可能是由运行时类路径中的JSF API和impl库中的冲突和/或不匹配引起的。您需要确保您的运行时类路径在API和impl库中没有冲突和/或不匹配。

鉴于您正在使用Maven并使用准系统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-apijsf-impl坐标。