2013-10-09 17 views
2

使用時RF4的方式來構建豐富的我遇到了一個奇怪的例外奇怪的異常使用C時:的foreach,豐富的:列,下面是一個例子來重現問題:列,複合材料構件

page.xhtml

<?xml version="1.0" encoding="ISO-8859-1"?> 
<!DOCTYPE html> 
<html 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:a4j="http://richfaces.org/a4j" 
    xmlns:c="http://java.sun.com/jsp/jstl/core" 
    xmlns:my="http://java.sun.com/jsf/composite/my" 
    xmlns:rich="http://richfaces.org/rich"> 
<h:head/> 
<h:body> 
<f:view> 
    <h:form> 
     <a4j:commandButton value="2 columns" action="#{testBean.creat2Headers()}" render="@form" /> 
     <a4j:commandButton value="5 columns" action="#{testBean.creat5Headers()}" render="@form" /> 
     <a4j:outputPanel id="patientMain" layout="block"> 
      <rich:dataTable id="produitTable" var="produit" value="#{testBean.table}"> 
       <c:forEach items="#{testBean.header}" var="header"> 
        <rich:column> 
         <my:input valueSelected="#{testBean.testValue}" /> 
        </rich:column> 
       </c:forEach> 
      </rich:dataTable> 
    test 
      <my:input valueSelected="#{testBean.testValue}" /> 
     </a4j:outputPanel> 
    </h:form> 
</f:view> 

input.xhml用於複合部件,用於輸入的ID必須在那裏。

<?xml version="1.0" encoding="ISO-8859-1" ?> 


<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" 
xmlns:f="http://java.sun.com/jsf/core" 
xmlns:h="http://java.sun.com/jsf/html" xmlns:a4j="http://richfaces.org/a4j" 
xmlns:rich="http://richfaces.org/rich" 
xmlns:composite="http://java.sun.com/jsf/composite"> 
    <composite:interface> 
    <composite:attribute name="valueSelected" required="true"/> 
    </composite:interface> 

    <composite:implementation> 
    <h:inputText value="#{cc.attrs.valueSelected}" id="input"/> 
    </composite:implementation> 
</html> 

Java代碼TestBean.java

@ManagedBean 
@ViewScoped 
public class TestBean implements Serializable{ 
private List<String> table = new ArrayList<String>(); 

private List<String> header=new ArrayList<String>(); 

private Integer testValue=0; 

public TestBean(){ 
logger.info("bean created"); 
this.table.add("ligne1"); 
this.header.add("header1"); 
this.header.add("header2"); 
} 

public void creat2Headers(){ 
this.header.clear(); 
this.header.add("header1"); 
this.header.add("header2"); 
} 

public void creat5Headers(){ 
this.header.clear(); 
this.header.add("header1"); 
this.header.add("header2"); 
this.header.add("header3"); 
this.header.add("header4"); 
this.header.add("header5"); 
} 

public List<String> getTable() { 
return this.table; 
} 

public void setTable(List<String> _table) { 
this.table = _table; 
} 

public List<String> getHeader() { 
return this.header; 
} 

public void setHeader(List<String> _header) { 
this.header = _header; 
} 

public Integer getTestValue() { 
return this.testValue; 
} 

public void setTestValue(Integer _testValue) { 
this.testValue = _testValue; 
} 

} 

當你點擊該按鈕creat2columns,然後點擊creat5columns,你得到的異常

09/10 14:21:44,638 Grave [javax.enterprise.resource.webcontainer.jsf.application] JSF1007 : ID de composant j_idt4-j_idt88-input is double in the view. 
09/10 14:21:44,639 Grave [javax.enterprise.resource.webcontainer.jsf.application] +id: j_id1 
type: [email protected] 
    +id: javax_faces_location_HEAD 
    type: [email protected] 
    +id: __rf_skinning_resource 
    type: [email protected] 
    +id: j_id10 
    type: [email protected] 
    +id: j_id11 
    type: [email protected] 
    +id: j_id12 
    type: [email protected] 
    +id: j_id13 
    type: [email protected] 
    +id: j_idt1 
    type: <html xmlns="http://www.w3.org/1999/xhtml"> 
    +id: j_idt2 
    type: [email protected] 
    +id: j_idt70 
    type: [email protected] 
    +id: j_idt4 
    type: [email protected] 
     +id: j_idt71 
     type: [email protected] 
     +id: j_idt72 
     type: [email protected] 
     +id: patientMain 
     type: [email protected] 
     +id: produitTable 
     type: [email protected] 
      +id: j_idt84 
      type: [email protected] 
      +id: j_idt85 
      type: [email protected] 
       +id: j_id3 
       type: [email protected] 
       +id: input 
       type: [email protected] 
      +id: j_idt86 
      type: [email protected] 
      +id: j_idt87 
      type: [email protected] 
       +id: j_id3 
       type: [email protected] 
       +id: input 
       type: [email protected] 
     +id: j_idt7 
     type: 
     tt 
     +id: j_idt88 
     type: [email protected] 
      +id: j_id3 
      type: [email protected] 
      +id: input <=============== 
      type: [email protected] 
      +id: input <=============== 
      type: [email protected] 
    +id: j_idt63 
    type: 
</html> 

請幫我

在此先感謝

+0

用h:datatable和h:列替換rich:column和rich:datatable仍然有同樣的問題。 – liumin

回答

-1

您的複合組件具有固定的ID,您不需要。

+0

複合組件生成的''不是命名容器,是嗎?它的id是導致問題的原因,基於堆棧跟蹤。 – Makhiel

+0

複合組件命名容器,所以你可以自由使用固定的ID。 – Andrey

+0

inputText不是命名容器,但是它是在父命名容器範圍內具有此類id的唯一孩子。 – Andrey

0

它看起來像在RichFaces/JSF中的錯誤。 例如指這一個: https://issues.jboss.org/browse/RF-13103

我也遇到了很多不同的組件相同的問題至今(RichFaces的迭代成分,也JBoss Seam的S:裝飾)。 有趣的是,您遇到了JSF組件的問題,如果您能夠在不使用RichFaces組件的情況下重現問題,請記錄針對JSF的問題,或給我一個可重複的示例,我會這樣做。

嘗試將JSF升級到最新版本,可能會有幫助。

現在,RF-13103中描述的解決方法應該有所幫助(以性能爲代價),而不是UITree,請使用org.richfaces.component.UIOutputPanel(或其他包裝有問題的區域)。

+0

你可以使用相同的例子,只需用h:datatable和h:column替換rich:datatable和rich:column。 – liumin

+0

a4j:outputPanel和a4j:commandButton組件仍然會保留在那裏 – Andrey