我在我的 JSF 页面中随机出现重复的 ID 错误,并且在所有情况下,重复的 ID 都是自动生成的(如 j_id15)。
我在页面中的指定 ID 中没有任何重复项。而且问题并不一致,我的意思是,页面视图可能会引发重复 ID 错误,并且下次我发送同一页面的请求时,它运行得很好,没有任何错误。这并不特定于单个页面,我的项目中有多个页面都有相同的问题。
从 myfaces 2.0.5 升级到 myfaces 2.0.14(最新 2.0.x 版本)后问题开始出现
这是 myfaces 实现中的错误吗?还是我做错了什么?
堆栈跟踪如下所示:
Caused by: java.lang.IllegalStateException: Client-id : j_id15 is duplicated in the faces tree. Component : posSelectionFrm:posSelSubview_first:posHasAccessTable:j_id15, path: ...[Class: javax.faces.component.UINamingContainer,Id: posSelSubview_first][Class: javax.faces.component.html.HtmlDataTable,Id: posHasAccessTable][Class: javax.faces.component.UIColumn,Id: titleColumn2][Class: com.sun.facelets.compiler.UIInstructions,Id: j_id15]}
at org.apache.myfaces.application.StateManagerImpl.checkForDuplicateIds(StateManagerImpl.java:280)
at org.apache.myfaces.application.StateManagerImpl.checkForDuplicateIds(StateManagerImpl.java:302)
at org.apache.myfaces.application.StateManagerImpl.checkForDuplicateIds(StateManagerImpl.java:302)
at org.apache.myfaces.application.StateManagerImpl.checkForDuplicateIds(StateManagerImpl.java:302)
at org.apache.myfaces.application.StateManagerImpl.checkForDuplicateIds(StateManagerImpl.java:302)
at org.apache.myfaces.application.StateManagerImpl.checkForDuplicateIds(StateManagerImpl.java:302)
at org.apache.myfaces.application.StateManagerImpl.checkForDuplicateIds(StateManagerImpl.java:302)
at org.apache.myfaces.application.StateManagerImpl.checkForDuplicateIds(StateManagerImpl.java:302)
at org.apache.myfaces.application.StateManagerImpl.checkForDuplicateIds(StateManagerImpl.java:302)
at org.apache.myfaces.application.StateManagerImpl.checkForDuplicateIds(StateManagerImpl.java:302)
at org.apache.myfaces.application.StateManagerImpl.saveView(StateManagerImpl.java:220)
at javax.faces.application.StateManager.saveSerializedView(StateManager.java:113)
at javax.faces.application.StateManagerWrapper.saveSerializedView(StateManagerWrapper.java:41)
at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:617)
at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:116)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:239)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)
... 71 more
而且,我意识到默认情况下 myfaces 不应该检查自动生成的 ID 的重复项。但为了确保,我在 web.xml 中定义了以下设置:
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.CHECK_ID_PRODUCTION_MODE</param-name>
<param-value>false</param-value>
</context-param>
但问题仍然存在。
该项目使用 Apache MyFaces 2.0.14、Facelets 1.1.15、RichFaces 3.3.3.Final 在 Tomcat 6.0 上运行。