我正在开发 Spring3/JSF2/Primefaces3.5 应用程序。
我面临的问题是某些 Primefaces 组件(p:autocomplete、p:calendar 和 p:selectOneMenu)无法在浏览器中正确呈现。该问题在许多页面中随机出现。如果我重新加载页面(例如通过 F5 键),问题就会得到纠正,并且组件会按应有的方式呈现。
.xhtml 文件:
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:p="http://primefaces.org/ui">
<h:form id="mainForm">
....
<f:validateBean>
<table class="listing form" cellpadding="0" cellspacing="0">
...
(some p:inputText elements)
...
<tr class="bg">
<td class="first"><strong>Marque :</strong></td>
<td class="last">
<p:autoComplete
label="Marque"
value="#{montureBean.marque}"
completeMethod="#{montureBean.autocompleteMarque}"
var="item"
itemLabel="#{item.intitule}"
itemValue="#{item}"
converter="#{montureBean.marqueConverter}"
dropdown="true"/>
<p:commandLink onclick="dlgMarque.show()" immediate="true">
<img src="/images-main/add-icon.gif" border="0" alt="Ajouter Marque" class="img-action"/>
</p:commandLink>
</td>
</tr>
<tr class="bg">
<td class="first"><strong>Matière :</strong></td>
<td class="last">
<p:autoComplete
label="Matière"
value="#{montureBean.matiere}"
completeMethod="#{montureBean.autocompleteMatiere}"
var="item"
itemLabel="#{item.intitule}"
itemValue="#{item}"
converter="#{montureBean.matiereConverter}"
dropdown="true"/>
<p:commandLink onclick="dlgMatiere.show()" immediate="true">
<img src="/images-main/add-icon.gif" border="0" alt="Ajouter Matière" class="img-action"/>
</p:commandLink>
</td>
</tr>
</table>
</f:validateBean>
</h:form>
</ui:composition>
以下是为 p:autocomplete 生成的代码示例:
错误的渲染:
<span aria-multiline="false" aria-disabled="false" role="textbox" id="mainForm:j_id_q_1i" class="ui-autocomplete">
<input id="mainForm:j_id_q_1i_input" name="mainForm:j_id_q_1i_input" class="ui-autocomplete-input ui-inputfield ui-widget ui-state-default ui-corner-left" autocomplete="off" value="" type="text">
<input id="mainForm:j_id_q_1i_hinput" name="mainForm:j_id_q_1i_hinput" autocomplete="off" value="0" type="hidden">
<button class="ui-button ui-widget ui-state-default ui-corner-right ui-button-icon-only" type="button">
<span class="ui-button-icon-primary ui-icon ui-icon-triangle-1-s"></span>
<span class="ui-button-text"> </span>
</button>
<div id="mainForm:j_id_q_1i_panel" class="ui-autocomplete-panel ui-widget-content ui-corner-all ui-helper-hidden ui-shadow"></div>
</span>
正确渲染:
<span id="mainForm:j_id_q_1i" class="ui-autocomplete">
<input id="mainForm:j_id_q_1i_input" name="mainForm:j_id_q_1i_input" type="text" class="ui-autocomplete-input ui-inputfield ui-widget ui-state-default ui-corner-left" autocomplete="off" value="" />
<input id="mainForm:j_id_q_1i_hinput" name="mainForm:j_id_q_1i_hinput" type="hidden" autocomplete="off" value="0" />
<button class="ui-button ui-widget ui-state-default ui-corner-right ui-button-icon-only" type="button">
<span class="ui-button-icon-primary ui-icon ui-icon-triangle-1-s"></span>
<span class="ui-button-text"> </span>
</button>
<div id="mainForm:j_id_q_1i_panel" class="ui-autocomplete-panel ui-widget-content ui-corner-all ui-helper-hidden ui-shadow"></div>
</span>
<script id="mainForm:j_id_q_1i_s" type="text/javascript"><!--
$(function(){PrimeFaces.cw('AutoComplete','widget_mainForm_j_id_q_1i',{id:'mainForm:j_id_q_1i'});});
//--></script>
我注意到:
- 许多属性被分配给第一个跨度而不是输入,
- 两个输入元素没有在错误的渲染中关闭>代替/>
- 有一个javascript函数出现在正确的渲染中,我们在错误的情况下看不到。
这是一个错误还是我做错了什么。注意:我使用 p:layout 进行页面组织,使用 f:validation 验证输入元素。