8 Replies Latest reply on Nov 6, 2008 11:36 PM by visumagic

    Iteration in JSF is not working

    visumagic

      Hi


      JSF Iteration in seam level of context values are not working.
      Even I tried with c:forEach, it's working but I'm not able to refer properties of iteration var(coursei) in side  loop.


      where collegeCources is a





      <rich:tabPanel switchType="ajax" >
                              <ui:repeat value="#{CollegeProfile.collegeCources}" var="coursei">
                      
                                        <rich:tab >
                                              <f:facet name="label">
                                                  <h:panelGroup>
                                                              
                                                      <h:outputText value="#{coursei.title}" />
                                                  </h:panelGroup>
                                              </f:facet>
                                 </rich:tab>
                      </ui:repeat>
              </rich:tabPanel>



      CollegePorfile
      ....
      @DataModel
          List<Course> collegeCources;
          @Factory
          public List<Course> getCollegeCources() {
      ...




      plz help me


      thanks
      raghu

        • 1. Re: Iteration in JSF is not working
          mail.micke

          Have you tried #{collegeCources} instead of #{CollegeProfile.collegeCources} ?


          Don't use @DataModel much myself but think that it is being outjected.

          • 2. Re: Iteration in JSF is not working
            visumagic

            Thanks for your quick reply,


            I tried it , but no use, I have seen couple of forms reporting on Seam iteration, but still need bug it more, With out iterator writing dynamic pages is horrible ..


            thanks
            raghu

            • 3. Re: Iteration in JSF is not working
              mail.micke

              Another thing is that your factory method is the getter, you should probably rename that method to something like initCollegeCources, try something like this:


              @DataModel
              List<Course> collegeCources;
              
              @Factory("collegeCources")
              public List<Course> initCollegeCources() {
              
              }
              



              And then access it as #{collegeCources}, it that doesn't work something else is the problem.


              Alternatively you could skipp the @DataModel stuff entierly and do what I usually do. This:


              List<Course> collegeCources;
              
              @Create
              public void initCollegeCources() {
                  collegeCources = // create the college cources.
              }
              
              public List<Course> getCollegeCources(){}
              
              



              And then access it like this in the page #{CollegeProfile.collegeCources}, gievn that CollegeProfile is the name of the backing bean/component.


              cheers,
              micke

              • 4. Re: Iteration in JSF is not working
                mail.micke

                Hmm, is iteration not working at all or is it just with the tabbed panel? Haven't tried creating tabs dynamically myself.


                If it is the tabbed panel component, you might have better luck asking in the richfaces forum.

                • 5. Re: Iteration in JSF is not working
                  visumagic
                  Ya, there is no prob with tabpanel, The iteration itself is not happening, I'm able to print the list on the page.
                  But Iteration is not really happening with ui:repeat , c:forEach is working fine but , the index var is not available in seam context, only i can print the value(toString) but no inner properties are not available ..

                  look at this   


                  `<c:forEach items="#{CollegeProfile.collegeCources}" var="coursei">
                                                          <h:outputText value="#{coursei.title}"/>
                                  </c:forEach>

                  `

                  above code is not working .. throwing following exception :

                  `javax.el.PropertyNotFoundException: /collegeProfile.xhtml @70,48 value="#{coursei.title}": Property 'title' not found on type java.lang.String
                  `

                  Following code is working upto displaying the value. coursei.toString() printing..
                  `       <c:forEach items="#{CollegeProfile.collegeCources}" var="coursei">
                                                          <h:outputText value="#{coursei}"/>
                          </c:forEach>`


                  im confused how to use it...

                  plz help me ,
                  raghu
                  • 6. Re: Iteration in JSF is not working
                    visumagic

                    hi all,
                    i guess this is a bug, any one plz confirm me.
                    Description:
                    While using iterators c:forLoop,ui:repeat,on list type variables in seam context, the indexing variable's properties are not available inside the loop.


                    example:


                    <ui:repeat value="#{CollegeProfile.collegeCourses}" var="coursei">
                    <s:label title="${coursei.title}"></s:label>
                    </ui:repeat>
                    



                    thanks
                    raghu

                    • 7. Re: Iteration in JSF is not working
                      visumagic

                      hi
                      Here is the result of my long investigation ,
                      I'm using jboss-4.2.3.GA pack, which is using JSP Engine: 2.1


                      According to JBoss EL docs , it's incompatible with JSP 2.1.



                      Incompatibility with JSP 2.1 — JBoss EL can't currently be used with JSP 2.1 as the compiler rejects expressions with parameters in. So, if you want to use this extension with JSF 1.2, you will need to use Facelets. The extension works correctly with JSP 2.0. 

                      Seam Docs


                      So this might be the reason for this , I'm still not resolved it, but seriously working on it.



                      Note:


                      Following is the code to find version of JSP Engin in any server.  


                      <div>
                                      Servlet Engine:
                                      <%= session.getServletContext().getMajorVersion() %>.<%= session.getServletContext().getMinorVersion() %>
                              </div>
                              <div>
                                      JSP Engine:
                                      <%= JspFactory.getDefaultFactory().getEngineInfo().getSpecificationVersion()%>
                              </div>            
                              <div>
                                      Application Server:
                                      <%= application.getServerInfo()%>
                              </div>



                      • 8. Re: Iteration in JSF is not working
                        visumagic

                        HI ALL,


                        This is working.. thanks for your help.


                        thanks Mikael, I'm following your suggestion,it's working pretty.


                        I did a mistake in query itself, but took long time to rectify it. Now I'm able to generate Dynamic tabs using forEach.


                        As I'm novice in seam , it's taking long time to debug the issues.
                        But It is really challenging to understand complex code. But any how nice experience. This issue took 1 full day,some times I was about to give-up but took it as challenging, now I completed.


                        thanks
                        raghu




                        last works for now...
                        Seam is excellent but really takes much time for self learners like me.It's is not simple as other frameworks like Struts,Hibernate...If I do any mistake-some times it will work fine but gives performance issues.experience will give lot of knowledge.