复合组件在ajax调用后呈现两次
我对复合组件有一种奇怪的情况。我在我的web应用程序中都在使用它,但是现在我注意到,如果我更新一个包含复合组件的表单,组件会被渲染两次(有时) 我的组件(比如称为复合组件在ajax调用后呈现两次,ajax,jsf,primefaces,jsf-2.2,composite-component,Ajax,Jsf,Primefaces,Jsf 2.2,Composite Component,我对复合组件有一种奇怪的情况。我在我的web应用程序中都在使用它,但是现在我注意到,如果我更新一个包含复合组件的表单,组件会被渲染两次(有时) 我的组件(比如称为datecc)定义如下: <?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-t
datecc
)定义如下:
<?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:composite="http://java.sun.com/jsf/composite" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui">
<h:body>
<composite:interface>
<composite:attribute name="value"/>
<composite:attribute name="shortFormat"/>
<composite:attribute name="style"/>
<composite:attribute name="styleClass"/>
<composite:attribute default="false" name="inputLabel"/>
</composite:interface>
<composite:implementation>
<span id="#{cc.clientId}">
<h:outputText rendered="#{not cc.attrs.inputLabel}" style="#{cc.attrs.style}" styleClass="#{cc.attrs.styleClass}" value="#{cc.attrs.value}">
<f:convertDateTime pattern="#{cc.attrs.shortFormat ? 'dd/MM/yy' : 'dd/MM/yyyy'}" timeZone="#{timezone}"/>
</h:outputText>
<span>asdasdfasdf</span>
<h:inputText disabled="true" rendered="#{cc.attrs.inputLabel}" style="#{cc.attrs.style}" styleClass="#{cc.attrs.styleClass}" value="#{cc.attrs.value}">
<f:convertDateTime pattern="#{cc.attrs.shortFormat ? 'dd/MM/yy' : 'dd/MM/yyyy'}" timeZone="#{timezone}"/>
</h:inputText>
</span>
</composite:implementation>
</h:body>
</html>
asdasdfasdf
我从中调用它的页面与此类似:
<h:form id="form">
<p:dataTable id="rowsTable" value="#{myBean.rows}" var="it"
selectionMode="single" selection="#{myBean.selectedRow}" rowKey="#{it.key}"
rowStyleClass="#{myBean.isRed(it) ? 'red' : null}">
<p:ajax event="rowSelect" update=":menuForm :detailForm :contextualMenu"/>
<column>....</column>
<column><mycc:datecc value="#{it.date}" inputLabel="true" /></column>
</p:dataTable>
</h:form>
<h:form id="detailForm>
<!-- this field is rendered twice once I select a row in the above table -->
<mycc:datecc value="#{myBean.selectedRow.date}" inputLabel="true" />
</h:form>
....
我通过实现下面的类解决了我的问题
package com.company.faces.cc;
import javax.faces.component.FacesComponent;
import javax.faces.component.NamingContainer;
import javax.faces.component.UIInput;
import javax.faces.component.UINamingContainer;
@FacesComponent("inputDate")
public class Date extends UIInput implements NamingContainer {
@Override
public String getFamily() {
return UINamingContainer.COMPONENT_FAMILY;
}
}
虽然我真的不知道为什么这解决了这个问题,因为它没有给组件添加太多内容。您的jsf版本是什么-?如果低于Mojarra 2.2.5,请升级到新版本,好吗?我正在使用Mojarra 2.1.29在Glassfish3上部署应用程序-03@MahendranAyyarsamyKandiar我更新了JSF,现在我有了Mojarra 2.2.9,但问题仍然存在。有什么帮助吗?为任何登陆这里的可怜的灵魂。我们也遇到了同样的问题,但升级到2.2.18后就解决了。至于原因,我不知道,因为找不到Mojarra的发行说明。