我有一个带有数据表的 JSF 应用程序。每行都有一个“commandLink”。单击行的 commandLink 时,必须在控制台上显示行数据。
点击commandLink时出现错误,错误如下:
component with duplicate id "dataTable1:col1" found
viewId=/UserHome.xhtml
location=E:\workspaces_eclipse\webService\.metadata\.plugins \org.eclipse.wst.server.core\tmp2\wtpwebapps\JSF_Demo\UserHome.xhtml
phaseId=RENDER_RESPONSE(6)
Caused by:
java.lang.IllegalStateException - component with duplicate id "dataTable1:col1" found
at org.apache.myfaces.view.facelets.compiler.CheckDuplicateIdFaceletUtils.checkIds(CheckDuplic ateIdFaceletUtils.java:100)
该错误表明组件具有相同的 ID,但是我尝试为数据表的每个元素提供不同的“id”。
JSF 文件“UserHome.xhtml”的源代码如下:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Resource Net 1.0</title>
<h:outputStylesheet library="css" name="table-style.css"></h:outputStylesheet>
</h:head>
<h:body>
<div align="center">
<table width="90%" height="100%" border="0" style="cellspacing:0; border-radius:10px ;box-shadow: 0px 0px 15px 10px #888888">
<tr>
<td>
<h2><div align="center">Resource Net 1.0</div></h2>
</td>
</tr>
<tr>
<td>
2. Generated by Map :
<h:selectOneMenu value="#{userHomeListener.favCoffee2}">
<f:selectItems value="#{userHomeListener.allDomains}" />
</h:selectOneMenu>
</td>
</tr>
<tr>
<td>
<h:dataTable value="#{userHomeListener.documents}" var="doc"
binding="#{userHomeListener.documentsTable}"
id="dataTable1"
styleClass="order-table"
headerClass="order-table-header"
rowClasses="order-table-odd-row,order-table-even-row"
border="1">
<h:column id="col1">
<f:facet name="header1">Document ID</f:facet>
#{doc.docID}
</h:column>
<h:column id="col2">
<f:facet name="header2">Document Name</f:facet>
#{doc.docName}
</h:column>
<h:column id="col3">
<f:facet name="header3">Document Link</f:facet>
<h:form id="form1">
<h:commandLink id="link" value="#{doc.docLink}" action="#{userHomeListener.getRowData}"></h:commandLink>
</h:form>
</h:column>
<h:column id="col4">
<f:facet name="header4">Upload Date</f:facet>
#{doc.uploadDate}
</h:column>
</h:dataTable>
<h:commandButton value="get row data" ></h:commandButton>
</td>
</tr>
</table>
</div>
</h:body>
我的代码有问题吗?请提出解决此问题的方法。
提前致谢。