4 Replies Latest reply on Feb 8, 2008 6:55 AM by vicky123

    Problem implementing filters

    vicky123

      Hi All,
      I am facing some problem while implementing filters.

      My code:-

       <core:filter name="companyFilter">
       <core:name>companyFilter</core:name>
       <core:parameters>
       <key>currentCompanyId</key>
       <value>#{currentCompanyId}</value>
       </core:parameters>
       </core:filter>
      
       <core:managed-persistence-context
       name="filteredEntityManager"
       persistence-unit-jndi-name="java:/pEntityManagerFactory">
       <core:filters>
       <value>#{companyFilter}</value>
       </core:filters>
       </core:managed-persistence-context>
      


      Exception:-
      Caused by: org.jboss.seam.RequiredException: @In attribute requires non-null value: userManage.filteredEntityManager


      Session bean:-
       @In
       protected EntityManager filteredEntityManager;


      Entity bean:-
      @FilterDef(name = "companyFilter", parameters = {@ParamDef(name = "currentCompanyId", type = "integer")})
      @Filter(name = "companyFilter", condition = "icompanyId <= :currentCompanyId")
      


      When I change componets.xml(filter removed) to this
      <core:managed-persistence-context
       name="filteredEntityManager"
       persistence-unit-jndi-name="java:/pEntityManagerFactory">
       </core:managed-persistence-context>

      it works fine without filters(I know there is no filter).

      And I also see an error in eclipse saying
      cvc-complex-type.2.4.c:The matching wild card is strict, but no declaration can be found for element 'code:filter'

      cvc-complex-type.2.4.c:The matching wild card is strict, but no declaration can be found for element 'core:managed-persistence-context'


      Can anyone tell me whats going wrong?
      Thanks in advance.

      -Vivek

        • 1. Re: Problem implementing filters
          pmuir

          You probably need either auto-create=true in components.xml or create=true on the @In

          • 2. Re: Problem implementing filters
            vicky123

            I added auto-create in components.xml but it didn't work.

            <core:managed-persistence-context
             name="filteredEntityManager"
             auto-create="true"
             persistence-unit-jndi-name="java:/pEntityManagerFactory">
             <core:filters>
             <value>#{companyFilter}</value>
             </core:filters>
             </core:managed-persistence-context>


            Then i added create=true

            @In(create=true)
             protected EntityManager filteredEntityManager;
            


            Exception was same in both the cases.

            I am wondering if this error in eclipse is causing the problem?
            cvc-complex-type.2.4.c:The matching wild card is strict, but no declaration can be found for element 'code:filter'
            



            cvc-complex-type.2.4.c:The matching wild card is strict, but no declaration can be found for element 'core:managed-persistence-context'
            


            • 3. Re: Problem implementing filters
              vicky123

              Can anyone please tell me how to solve this problem in eclipse?

              cvc-complex-type.2.4.c:The matching wild card is strict, but no declaration can be found for element 'code:filter'


              cvc-complex-type.2.4.c:The matching wild card is strict, but no declaration can be found for element 'core:managed-persistence-context'


              Is this error in eclipse acting as a root problem while implementing the filters?

              Its been two days I am not able to solve this problem.

              Thanks in advance.

              -Vivek



              • 4. Re: Problem implementing filters
                vicky123

                Thank you all.

                I changed my components.xml to this and it worked. And rest all is same.

                 <persistence:filter name="companyFilter">
                 <persistence:name>companyFilter</persistence:name>
                 <persistence:parameters>
                 <key>currentCompanyId</key>
                 <value>#{currentCompanyId}</value>
                 </persistence:parameters>
                 </persistence:filter>
                
                 <persistence:managed-persistence-context
                 name="filteredEntityManager"
                 auto-create="true"
                 persistence-unit-jndi-name="java:/PEntityManagerFactory">
                 <persistence:filters>
                 <value>#{companyFilter}</value>
                 </persistence:filters>
                 </persistence:managed-persistence-context>