1 2 Previous Next 16 Replies Latest reply on Nov 23, 2011 1:12 AM by Jason Porter

    Correct annotation usage?

    JEE 4 Hire Newbie

      Can using @Named, @Inject coexist just fine with the following?
      Am I causing any problems?  I even tried to use @FacesConverter, @ManagedBean.
      Nothing works.  Please advise.
      In order to get PrimeFaces to work, I have to use the following:



        • 1. Re: Correct annotation usage?
          JEE 4 Hire Newbie

          Correction:


          I removed the entries from faces-config.xml and was able to get the following working.
          Am I causing any problems by using both @Named and @ManagedBean together? 
          PrimeFaces will not work with only @Named.



          @FacesConverter(playerConverter)
          public class PlayerConverter implements Converter, Serializable {
            ...
          }




          @SessionScoped
          @Named
          @ManagedBean
          public class AutoCompleteBean implements Serializable {
            ...
          }

          • 2. Re: Correct annotation usage?
            JEE 4 Hire Newbie

            Does @Named have a bug? 
            What is the difference between @Named and @ManagedBean?

            • 3. Re: Correct annotation usage?
              MIklos Piklos Newbie

              No @Named does not have a bug. You shouldn't mix the two. It is enough to declare it as @Named, it will automatically be visible to JSF.
              I guess that it doesn't work because you use the wrong @SessionScoped.
              Are you using


              javax.faces.bean.SessionScoped



              or


              javax.enterprise.context.SessionScoped



              ?

              • 4. Re: Correct annotation usage?
                Jason Porter Master

                This is yet another instance of JSF missing the bandwagon for things, and of course because it's in the spec it probably won't ever go away. They may be deprecated in a newer spec, but they won't ever go away :( The argument was using plain JSF w/o CDI (i.e. in a servlet container). We'd like to see the Servlet container idea become an actual EE profile which would be even slimmer than the current Web Profile and would also contain CDI 1.1. No idea if this will happen or not though.

                • 5. Re: Correct annotation usage?
                  RatKing Newbie

                  I do the following, and it work well.


                  1. create a new file WEB-INF/beans.xml


                  2. copy the following jars(http://in.relation.to/Bloggers/Seam31Beta4Released) into WEB-INF/lib



                  seam-faces.jar
                  seam-faces-api.jar
                  seam-international.jar
                  seam-international-api.jar
                  seam-persistence.jar
                  seam-persistence-api.jar
                  seam-security.jar
                  seam-security-api.jar
                  seam-transaction.jar
                  seam-transaction-api.jar
                  solder-api.jar
                  solder-impl.jar
                  solder-logging.jar




                  3. modify PlayerConverter.java



                  import javax.enterprise.context.RequestScoped;
                  import javax.faces.convert.Converter;
                  import javax.faces.convert.FacesConverter;
                  
                  @RequestScoped
                  @FacesConverter("player")
                  public class PlayerConverter implements Converter {
                  //...
                  }




                  4. modify AutoCompleteBean.java



                  import javax.enterprise.context.RequestScoped;
                  import javax.inject.Named;
                  
                  @Named
                  @RequestScoped
                  public class AutoCompleteBean {
                  // ...
                  }




                  5. remove the following lines from faces-config.xml:



                  <converter>
                      <converter-id>playerConverter</converter-id>
                      <converter-class>org.jboss.seam.examples.booking.PlayerConverter</converter-class>
                  </converter>
                  <managed-bean>
                      <managed-bean-name>autoCompleteBean</managed-bean-name>
                      <managed-bean-class>org.jboss.seam.examples.booking.AutoCompleteBean</managed-bean-class>
                      <managed-bean-scope>request</managed-bean-scope>
                  </managed-bean>




                  6. compile and delpoy the war in GlassFish 3.1.2(http://dlc.sun.com.edgesuite.net/glassfish/3.1.2/promoted/) (or JBoss7)


                  7. browse http://localhost:8080/prime-showcase

                  • 6. Re: Correct annotation usage?
                    RatKing Newbie

                    In my case, the converter id is player(@FacesConverter("player"))(is not playerConverter).
                    So, my selectOneMenu.xhtml is:




                    <p:selectOneMenu value="#{autoCompleteBean.selectedPlayer1}" effect="fade" *converter="player"*>
                        <f:selectItem itemLabel="Select One" itemValue="" />
                        <f:selectItems value="#{autoCompleteBean.players}" var="player" itemLabel="#{player.name}" itemValue="#{player}"/>
                    </p:selectOneMenu>



                    • 7. Re: Correct annotation usage?
                      JEE 4 Hire Newbie

                      No, I am using the endorsed:


                      javax.enterprise.context.SessionScoped

                      • 8. Re: Correct annotation usage?
                        JEE 4 Hire Newbie

                        Why do you prefer n GlassFish 3.1.2 over JBoss?

                        • 9. Re: Correct annotation usage?
                          hantsy bai Master

                          Currently, I encountered several problems when using Seam3, such as the Ajax problem(the ajax only works with JSF reference impl 2.0.2) and the frequent StateHolder exception(If I used JBoss 7.0.2, the JSF reference impl was updated to 2.1.3 FCS,  Richfaces components will throw such an exception frequently and did not work) ...I do not know if they are caused by the incompatibility between JSF scope and CDI scope, I always used CDI scopes in my applications.


                          Seam 2 filled the gap between JSF1.2 and EJB, why Seam 3 did not fill the gap between JSF and CDI?

                          • 10. Re: Correct annotation usage?
                            Jason Porter Master

                            Seam 3 is more about extending Java EE than filling gaps. And actually Seam 2 became much more than filling the EJB / JSF gap as well.


                            The problems you're encountering are JSF problems, they're not Seam problems. If you look at the history of Mojarra 2.x you'll see a big list of incompatibilities and breakage wrt component libraries, CDI integration, composite components, etc. It's not our fault it was broken when it shipped and people coded to the breakage, then when they went and fixed things up right it broke those things that were coded to the breakage.


                            I've said it before, JSF 2.0, especially Mojarra, was pushed out the door way too early both at a spec level and implementation level, it's not really up to us to fix their bugs.

                            • 11. Re: Correct annotation usage?
                              Jason Porter Master

                              JEE 4 Hire wrote on Nov 01, 2011 11:54:


                              Why do you prefer n GlassFish 3.1.2 over JBoss?


                              Glassfish 3.1.2 still contains a number of unpatched CDI integration incompatibilities which were there in 3.1.1. I believe they're all mentioned on the compatibility page.

                              • 12. Re: Correct annotation usage?
                                hantsy bai Master

                                Jason Porter wrote on Nov 01, 2011 17:18:


                                Seam 3 is more about extending Java EE than filling gaps. And actually Seam 2 became much more than filling the EJB / JSF gap as well.

                                The problems you're encountering are JSF problems, they're not Seam problems. If you look at the history of Mojarra 2.x you'll see a big list of incompatibilities and breakage wrt component libraries, CDI integration, composite components, etc. It's not our fault it was broken when it shipped and people coded to the breakage, then when they went and fixed things up right it broke those things that were coded to the breakage.

                                I've said it before, JSF 2.0, especially Mojarra, was pushed out the door way too early both at a spec level and implementation level, it's not really up to us to fix their bugs.


                                So what I can do currently? wait for the next generation JSF 2.2 and CDI 1.1?


                                I am confused that JSF2.x(now JSF 2 was updated to 2.1) and CDI(it was released the 4th service pack) are parts of JEE6, why so much problems when using them together.


                                JEE6 was released two years, and the two specs are also updated in these two years, why the experts did not seat side by side to fix the incompatibilities.


                                • 13. Re: Correct annotation usage?
                                  Jason Porter Master

                                  You could try using MyFaces. Short of that, yes wait.


                                  I don't know all the reasons why things happened the way they did. People have some speculations, but that's just their own opinions. The facts are this: JSF 2.0 was one of the first specs included in Java EE 6. CDI was the last one completed. Because of that the integration isn't there. Ed Burns is working diligently to get JSF to have tighter CDI integration for the next version of JSF. Also he's planning on putting some of the ideas of Seam and also CODI into the core of JSF.


                                  As for JSF being at 2.1, the 2.1 is a maintenance release of the specification. Because of the rules of the JCP a new feature such as CDI integration cannot be done in a maintenance release.

                                  • 14. Re: Correct annotation usage?
                                    hantsy bai Master

                                    Jason Porter wrote on Nov 02, 2011 00:17:


                                    You could try using MyFaces.


                                    But how to use MyFaces in JBoss 7, there is no guide for this.


                                    I tried to added a myfaces api and impl modules in JBoss 7 modules folder, but it does not work.


                                    http://community.jboss.org/message/636254

                                    1 2 Previous Next