2 Replies Latest reply on Jan 13, 2006 4:10 AM by cleonhar

    Again: Dublicate ID

    cleonhar Newbie

      Hi everybody.

      I hope sombody can help me. I have a problem using the @DataModel Annotation. I saw some other people had the same problem and I tried also the suggestions, but nothing worked.

      I use JBoss 4.0.3SP1 and Seam 1.0beta. I tried it with MyFaces 1.0.9 and 1.1.1 and 1.1.2-SNAPSHOT.

      Here is my VIEW:

      
      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition 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"
       template="../include/template.xhtml">
      
      <!-- content -->
      <ui:define name="content">
      <div class="section">
       <h1>Benutzer</h1>
      </div>
      <div class="section">
       <h:outputText value="Keine User gefunden" rendered="#{userlist != null and empty userlist}"/>
       <h:dataTable value="#{userlist}" var="u" rendered="#{not empty userlist}">
       <h:column>
       <f:facet name="header">Name</f:facet>
       #{u.uid}
       </h:column>
       <h:column>
       <f:facet name="header">Action</f:facet>
       <h:commandLink action="#{userservice.delete}">Delete</h:commandLink>
       </h:column>
       </h:dataTable>
      </div>
      <div class="section">
       <h:form>
       <fieldset class="buttonBox">
       <h:commandButton action="#{userservice.readAll}" value="Show" class="button"/>
       </fieldset>
       </h:form>
      </div>
      <div class="section">
       <h:form>
       <fieldset class="buttonBox">
       <h:commandButton action="add" value="Add" class="button"/>
       </fieldset>
       </h:form>
      </div>
      </ui:define>
      </ui:composition>
      
      


      I use the following Statefull Session Bean:

      
      import static org.jboss.seam.ScopeType.SESSION;
      
      import java.util.List;
      
      import javax.ejb.Interceptor;
      import javax.ejb.Stateful;
      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      
      import org.apache.log4j.Logger;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.annotations.datamodel.DataModel;
      import org.jboss.seam.annotations.datamodel.DataModelSelectionIndex;
      import org.jboss.seam.ejb.SeamInterceptor;
      
      import de.mobileview.m4.core.security.User;
      
      
      
      @Stateful
      @Scope(SESSION)
      @Name("userservice")
      @Interceptor(SeamInterceptor.class)
      public class UserServiceImpl implements UserService {
      
       @PersistenceContext (unitName="merlix")
       protected EntityManager em;
       private static final Logger log = Logger.getLogger(UserService.class);
      
       @DataModel
       private List <User> userlist;
       @DataModelSelectionIndex
       private int userIndex;
      
       @In(required=false)
       @Out(required=false)
       private User user;
      
       public UserServiceImpl() {
       super();
       log.debug("Constructor called");
       }
      
       private void setUser()
       {
       user = userlist.get(userIndex);
       log.info( userIndex + "=>" + user);
       }
      
       public String add() {
       em.persist (user);
       return "success";
       }
      
       public String update() {
       em.merge(user);
       return "success";
       }
      
       public String load() {
       //return (User)em.createQuery("from User where uid='"+user.getUid()+"'").getSingleResult();
       user=em.find(User.class,user);
       return "success";
       }
      
       public String delete(){
       if (userlist==null) return "success";
       setUser();
       em.remove(user);
       return "success";
       }
      
       public String refresh() {
       em.refresh(user);
       return "success";
       }
      
      
       @SuppressWarnings("unchecked")
       public String readAll() {
       userlist=em.createQuery("from User").getResultList();
       return "success";
       }
      }
      


      Here the faces-config:

      
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
      
      <faces-config>
       <application>
       <locale-config>
       <default-locale>de</default-locale>
       <supported-locale>de</supported-locale>
       <supported-locale>en</supported-locale>
       </locale-config>
       <message-bundle>UserMessages</message-bundle>
       </application>
       <navigation-rule>
       <from-view-id>/user/user.xhtml</from-view-id>
       <navigation-case>
       <from-outcome>success</from-outcome>
       <to-view-id>/user/user.xhtml</to-view-id>
       </navigation-case>
       <navigation-case>
       <from-outcome>add</from-outcome>
       <to-view-id>/user/adduser.xhtml</to-view-id>
       </navigation-case>
       <navigation-case>
       <from-action>#{userservice.delete}</from-action>
       <from-outcome>success</from-outcome>
       <to-view-id>/user/user.xhtml</to-view-id>
       </navigation-case>
       </navigation-rule>
       <navigation-rule>
       <from-view-id>/user/adduser.xhtml</from-view-id>
       <navigation-case>
       <from-outcome>success</from-outcome>
       <to-view-id>/user/edituser.xhtml</to-view-id>
       </navigation-case>
       </navigation-rule>
       <navigation-rule>
       <from-view-id>/user/edituser.xhtml</from-view-id>
       <navigation-case>
       <from-outcome>success</from-outcome>
       <to-view-id>/user/edituser.xhtml</to-view-id>
       </navigation-case>
       </navigation-rule>
      
       <application>
       <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
       </application>
      
       <application>
       <variable-resolver>org.jboss.seam.jsf.SeamVariableResolver</variable-resolver>
       </application>
      
       <lifecycle>
       <phase-listener>org.jboss.seam.jsf.SeamPhaseListener</phase-listener>
       </lifecycle>
      
      </faces-config>
      
      


      Filling the table with "userservice.readAll" works fine. But if I try to use the delete method i get a duplicate id error:

      java.lang.IllegalStateException: Duplicate id : _tagId2. Child could not be added.
       at javax.faces.component._ComponentChildrenList.checkAddAllowed(_ComponentChildrenList.java:95)
       at javax.faces.component._ComponentChildrenList.add(_ComponentChildrenList.java:76)
       at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:152)
       at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
       at com.sun.facelets.tag.ui.DefineHandler.apply(DefineHandler.java:58)
       at com.sun.facelets.tag.ui.InsertHandler.apply(InsertHandler.java:66)
       at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
       at com.sun.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:49)
       at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
       at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:248)
       at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:294)
       at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:273)
       at com.sun.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:121)
       at com.sun.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:116)
       at com.sun.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:49)
       at com.sun.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:95)
       at com.sun.facelets.FaceletViewHandler.buildView(FaceletViewHandler.java:400)
       at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:434)
       at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:372)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:109)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:292)
       at net.sf.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:108)
       at net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter.doFilter(SecurityEnforcementFilter.java:197)
       at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
       at net.sf.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:324)
       at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
       at net.sf.acegisecurity.wrapper.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:50)
       at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
       at net.sf.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:220)
       at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
       at net.sf.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:173)
       at net.sf.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:120)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       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.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       at org.apache.catalina.valves.FastCommonAccessLogValve.invoke(FastCommonAccessLogValve.java:481)
       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:856)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
       at java.lang.Thread.run(Thread.java:595)
      


      
      <UIViewRoot id="_id182" locale="de" renderKitId="HTML_BASIC" rendered="true" transient="false" viewId="/user/user.xhtml">
      <HtmlOutputText escape="true" id="_tagId2" rendered="false" transient="false" value="Keine User gefunden"/>
      <HtmlDataTable border="-2147483648" first="0" id="_tagId3" rendered="false" rowIndex="-1" rows="0" transient="false" var="u">
      <UIColumn id="_tagId4" rendered="true" transient="false"/>
      <UIColumn id="_tagId6" rendered="true" transient="false">
      <HtmlCommandLink action="#{userservice.delete}" id="_tagId8" immediate="false" rendered="true" transient="false"/>
      </UIColumn>
      </HtmlDataTable>
      <HtmlForm enctype="application/x-www-form-urlencoded" id="_tagId9" rendered="true" submitted="false" transient="false">
      <HtmlCommandButton action="#{userservice.readAll}" disabled="false" id="_tagId10" immediate="false" readonly="false" rendered="true" styleClass="button" transient="false" type="submit" value="Show"/>
      </HtmlForm>
      <HtmlForm enctype="application/x-www-form-urlencoded" id="_tagId11" rendered="true" submitted="false" transient="false">
      <HtmlCommandButton action="add" disabled="false" id="_tagId12" immediate="false" readonly="false" rendered="true" styleClass="button" transient="false" type="submit" value="Add"/>
      </HtmlForm>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
      <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> <title>Merlix 4</title> <link href="../include/css/screen.css" rel="stylesheet" type="text/css"/> </head> <body> <div id="document"> <div id="header"> <div id="status"> Welcome </div> </div> <div id="container"> <div id="sidebar"> <h1>Menu</h1> <a href="../user/user.jsf" shape="rect">User</a> </div> <div id="content">
      <div class="section"> <h1>Benutzer</h1> </div> <div class="section">
      </UIViewRoot>
      



      Any ideas?

      Thanks
      Claus


        • 1. Re: Again: Dublicate ID
          Gavin King Master

          You need to direct these issues to the MyFaces and/or Facelets forums. Jacob told me this stuff was fixed, but I'm not thoroughly convinced of that.

          This is due to MyFaces bugs, AFAIK.

          • 2. Re: Again: Dublicate ID
            cleonhar Newbie

            Hi,

            I am not sure whether this is a MyFaces problem. I changed the annotations a little bit. Then it works:

            @Stateful
            @Name("userservice")
            @Interceptor(SeamInterceptor.class)
            @Conversational(ifNotBegunOutcome="success")

            I added the Conversational-Annotation and start a transation with the @BEGIN Annotation before readAll. I end the transaction after the delete-Method with @END:

            
            
            @Stateful
            @Name("userservice")
            @Interceptor(SeamInterceptor.class)
            @Conversational(ifNotBegunOutcome="success")
            public class UserServiceImpl implements UserService {
            
             @PersistenceContext (unitName="merlix")
             protected EntityManager em;
             private static final Logger log = Logger.getLogger(UserService.class);
            
             @DataModel
             private List <User> userlist;
             @DataModelSelectionIndex
             private int userIndex;
            
             @In(required=false)
             @Out(required=false)
             private User user;
            
             public UserServiceImpl() {
             super();
             log.debug("Constructor called");
             }
            
             private void setUser()
             {
             user = userlist.get(userIndex);
             log.info( userIndex + "=>" + user);
             }
            
             @Begin @End
             public String add() {
             em.persist (user);
             return "success";
             }
            
            
             public String update() {
             em.merge(user);
             return "success";
             }
            
            
             public String load() {
             //return (User)em.createQuery("from User where uid='"+user.getUid()+"'").getSingleResult();
             user=em.find(User.class,user);
             return "success";
             }
            
             @End
             public String delete(){
             if (userlist==null) return "success";
             setUser();
             em.remove(user);
             userlist=null;
             return "success";
             }
            
             public String refresh() {
             em.refresh(user);
             return "success";
             }
            
            
             @SuppressWarnings("unchecked")
             @Begin
             public String readAll() {
             userlist=em.createQuery("from User").getResultList();
             return "success";
             }
            
             @Destroy @Remove
             public void destroy() {
             log.info("destroyed");
             }
            }
            


            But normally I would not use long running transactions in this case. Do I have to? Or is there a better way?

            What happens if I start the transaction before readAll() and the don`t delte anything but leave the page by clicking on link in my menu. Will the transaction be closed automatically?

            Bye
            Claus