JavaServer Faces - JSF RI 1.2 Duplicate component ID step2Form:j_id9 found in view.

Hi im using JSF RI 1.2 with Facelets

The problem shows when i create a back button :

let say we have pages : step1 and step2 and when im in step2 and click the back button

<h:commandButton action="back" value="#{msg.back}" immediate="true"/>

Then When I TRY to reSubmit the first page (step1) i get this error

maybe becouse the forms are allready added.

i Change the scope of all bean to session the problem is the same

when i submit if the id of the form is allready added i get the exception.

Can i make it more Struts like ? i mean if the id is alrleady created okei grab and get the content of this which is created and put the values in the new one .. dont show me crazy errors ? : )

can i do it ?

The Full Error :

java.lang.IllegalStateException: Duplicate component ID step2Form:j_id9 found in view.

at com.sun.faces.application.StateManagerImpl.checkIdUniqueness(StateManagerImpl.java:334)

at com.sun.faces.application.StateManagerImpl.checkIdUniqueness(StateManagerImpl.java:327)

at com.sun.faces.application.StateManagerImpl.saveSerializedView(StateManagerImpl.java:195)

at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:601)

at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:108)

at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:243)

at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:140)

at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)

at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)

at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)

at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)

at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)

at java.lang.Thread.run(Unknown Source)

Hmm Somethink New :

I have binded the <h:form with a fields of type HtmlForm in the backingBeans NOW the result is different

when the 3th time the form will be showed then throws the same exception .

example :

from step 1 go to step2 with next.

go back to step1 - lol it works ( this dont works early )

from step1 go to step 2 it works

now from step2 go back to step1 - exception

you can download the example from here :

http://isy-dc.com/~naiden/Wizzard.rar

the Valid data to be added for the first page is :

first feld : 3-8 symbols

secound field 3-8 sumbols

3th field : 8310282400

4 and 5th field must be the same 3-8 symbols

Message was edited by:

JOKe

Message was edited by:

JOKe

[3685 byte] By [JOKea] at [2007-11-26 23:14:00]
# 1
What version of the 1.2 RI?
rlubkea at 2007-7-10 14:12:30 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

I dont know what is the problem but this is the source code :

The Version is :

Created-By: 1.5.0_04-b05 (Sun Microsystems Inc.)

Specification-Title: JavaServer Faces

Specification-Version: 1.2

Implementation-Title: Sun Microsystems JavaServer Faces Implementation

Implementation-Version: 1.2_01-NIGHTLY_20060603

The Template :

<!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:ui="http://java.sun.com/jsf/facelets"

xmlns:h="http://java.sun.com/jsf/html"

xmlns:f="http://java.sun.com/jsf/core">

<f:loadBundle basename="resources" var="msg" />

<head>

<title><ui:insert name="pageTitle">Page Title</ui:insert></title>

<style type="text/css">

body {

font-family: Verdana, Arial, Helvetica, sans-serif;

font-size: 14px;

}

.header {

font-family: Verdana, Arial, Helvetica, sans-serif;

font-size: 18px;

}

.bottom {

font-family: Verdana, Arial, Helvetica, sans-serif;

font-size: 9px;

text-align: center;

vertical-align: middle;

color: #8E969D;

}

</style>

</head>

<body bgcolor="#ffffff">

<table style="border:1px solid #CAD6E0" align="center" cellpadding="0" cellspacing="0" border="0" width="800">

<tbody>

<tr>

<td class="header" height="42" align="center" valign="middle" width="100%" bgcolor="#E4EBEB">

<ui:insert name="pageHeader">Page Header</ui:insert>

</td>

</tr>

<tr>

<td height="1" width="100%" bgcolor="#CAD6E0"></td>

</tr>

<tr>

<td width="100%" colspan="2">

<table width="100%" style="height:150px" align="left" cellpadding="0" cellspacing="0" border="0">

<tbody>

<tr>

<td align="center" width="100%" valign="middle">

<ui:insert name="body">Page Body</ui:insert>

</td>

</tr>

</tbody>

</table>

</td>

</tr>

<tr>

<td colspan="2" valign="bottom" height="1" width="100%" bgcolor="#CAD6E0"></td>

</tr>

</tbody>

</table>

</body>

</html>

Step1 :

<!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: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">

<f:loadBundle basename="resources" var="msg" />

<ui:composition template="/templates/common.xhtml">

<ui:define name="pageTitle">JSF 1.2 and Facelets under Tomcat. KickStart Application</ui:define>

<ui:define name="pageHeader">JSF 1.2 Registration Application</ui:define>

<ui:define name="body">

<h:messages />

<p/>

<h:form id="step1Form" binding="#{person.form1}">

<table width="100%">

<tr>

<td align="right">${msg.prompt}</td>

<td><h:inputText label="Name" required="true"

id="name" value="#{person.name}" /></td>

<td align="left"><h:message showSummary="true"

showDetail="false" style="color: red; font-weight: bold;"

for="name" /></td>

</tr>

<tr>

<td align="right">${msg.username}</td>

<td><h:inputText binding="#{person.inputText}" id="username"

label="Username" required="true">

<f:validateLength maximum="8" minimum="3" />

</h:inputText></td>

<td align="left"><h:message for="username" /></td>

</tr>

<tr>

<td align="right">${msg.egn}</td>

<td><h:inputText label="Egn" validator="#{person.validateEgn}"

id="egn" binding="#{person.inputEgn}"/></td>

<td align="left"><h:message for="egn"></h:message></td>

</tr>

<tr>

<td align="right">${msg.password}</td>

<td>

<h:inputSecret id="pass" label="Password" required="true" binding="#{person.inputPassword}">

<f:validateLength minimum="3" maximum="6"/>

</h:inputSecret>

</td>

<td>

<h:message for="pass"></h:message>

</td>

</tr>

<tr>

<td align="right">${msg.confirm_password}</td>

<td>

<h:inputSecret id="cpass" label="Confirm Password" required="true" binding="#{person.inputCPassword}">

<f:validateLength minimum="3" maximum="6"/>

</h:inputSecret>

</td>

<td>

<h:message for="cpass"></h:message>

</td>

</tr>

<tr>

<td colspan="3" align="center"><h:commandButton type="submit"

id="submit" action="${person.submit}"

value="#{msg.next}"/></td>

</tr>

</table>

</h:form>

</ui:define>

</ui:composition>

</html>

Step 2 :

<!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:ui="http://java.sun.com/jsf/facelets"

xmlns:h="http://java.sun.com/jsf/html"

xmlns:f="http://java.sun.com/jsf/core">

<f:loadBundle basename="resources" var="msg" />

<ui:composition template="/templates/common.xhtml">

<ui:define name="pageTitle">JSF 1.2 and Facelets under Tomcat. KickStart Application</ui:define>

<ui:define name="pageHeader">Step 2 </ui:define>

<ui:define name="body">

<h:form id="step2Form" binding="#{step2.form2}">

#{msg.step2} #{person.name}!

<table>

<tr>

<td align="right">${msg.gender}</td>

<td align="left"><h:selectOneRadio

binding="#{step2.genderMenu}">

<f:selectItem itemValue="M" itemLabel="#{msg.gender_male}" />

<f:selectItem itemValue="F" itemLabel="#{msg.gender_female}" />

</h:selectOneRadio></td>

</tr>

<tr>

<td align="right">${msg.education}</td>

<td align="left"><h:selectManyListbox

binding="#{step2.educationList}">

<f:selectItem itemValue="1" itemLabel="#{msg.education_level1}" />

<f:selectItem itemValue="2" itemLabel="#{msg.education_level2}" />

<f:selectItem itemValue="3" itemLabel="#{msg.education_level3}" />

<f:selectItem itemValue="4" itemLabel="#{msg.education_level4}" />

</h:selectManyListbox></td>

</tr>

<tr>

<td align="right">

<!-- <h:commandLink value="#{msg.back}" action="back"></h:commandLink> -->

<h:commandButton action="back" value="#{msg.back}" id="back"/>

</td>

<td align="left"><h:commandButton action="#{step2.submit}"

value="#{msg.next}" id="submit2" /></td>

</tr>

</table>

</h:form>

</ui:define>

</ui:composition>

</html>

Step 3

<!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:ui="http://java.sun.com/jsf/facelets"

xmlns:h="http://java.sun.com/jsf/html"

xmlns:f="http://java.sun.com/jsf/core">

<f:loadBundle basename="resources" var="msg"/>

<ui:composition template="/templates/common.xhtml">

<ui:define name="pageTitle">JSF 1.2 and Facelets under Tomcat. KickStart Application</ui:define>

<ui:define name="pageHeader">Final Page</ui:define>

<ui:define name="body">

#{msg.final}

<h:form id="finalForm" binding="#{registration.form3}">

<h:outputText value="#{registration.regResult}"/>

<h:commandButton action="#{registration.save}" value="Save to Database" id="save"/>

<br/>

<h:commandButton action="back" value="#{msg.back}" immediate="true" id="back3"/>

</h:form>

</ui:define>

</ui:composition>

</html>

JOKea at 2007-7-10 14:12:30 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Hm i found the problem

the problem is in this two tags :

<h:selectOneRadio

binding="#{step2.genderMenu}">

<f:selectItem itemValue="M" itemLabel="#{msg.gender_male}" />

<f:selectItem itemValue="F" itemLabel="#{msg.gender_female}" />

</h:selectOneRadio>

<h:selectManyListbox

binding="#{step2.educationList}">

<f:selectItem itemValue="1" itemLabel="#{msg.education_level1}" />

<f:selectItem itemValue="2" itemLabel="#{msg.education_level2}" />

<f:selectItem itemValue="3" itemLabel="#{msg.education_level3}" />

<f:selectItem itemValue="4" itemLabel="#{msg.education_level4}" />

</h:selectManyListbox>

they are on step2 but whats the problem with this tags ?

JOKea at 2007-7-10 14:12:30 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

hmm now it work the problem is that they dont have id

the version that work looks like this :

<tr>

<td align="right">${msg.gender}</td>

<td align="left">

<h:selectOneRadio

binding="#{step2.genderMenu}" id="step2SelectOne">

<f:selectItem itemValue="M" itemLabel="#{msg.gender_male}" id="r1" />

<f:selectItem itemValue="F" itemLabel="#{msg.gender_female}" id="r2"/>

</h:selectOneRadio></td>

</tr>

<tr>

<td align="right">${msg.education}</td>

<td align="left"><h:selectManyListbox

binding="#{step2.educationList}" id="step2educationlist">

<f:selectItem itemValue="1" itemLabel="#{msg.education_level1}" id="m1"/>

<f:selectItem itemValue="2" itemLabel="#{msg.education_level2}" id="m2" />

<f:selectItem itemValue="3" itemLabel="#{msg.education_level3}" id="m3"/>

<f:selectItem itemValue="4" itemLabel="#{msg.education_level4}" id="m4"/>

</h:selectManyListbox></td>

</tr>

JOKea at 2007-7-10 14:12:30 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Hi,use id-tags in your jsf components so you can avoid duplicate IDs. (If you use copy and paste some components could have the same ID)Cu
Troilusa at 2007-7-10 14:12:30 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...