0 Replies Latest reply on Dec 9, 2008 2:15 PM by Mader Levap

    c:forEach problem.

    Mader Levap Newbie
      Hello again.

      <c:forEach> does not work. Just that. I use almost vanilia project generated by seam-gen.

      In bean:

      @Stateful
      @Name("navigation")
      @Scope(ScopeType.SESSION)
      public class Navigation implements NavigationInt
      {
      ...
      @DataModel
      private List<Module>  core_modules;
      ...

      @Factory("core_modules")
      public void loadAllowedModules()
      {
        String qStr = "select m from Module m";
        core_modules = entityManager.createQuery(qStr).getResultList();
      }

      public List<Module> getAllowedModules()
      {
        if (core_modules == null) loadAllowedModules();
        return core_modules;
      }
      ...
      }

      Interface, of course, have loadAllowedModules() and getAllowedModules().

      Entity:
      @Entity
      @Name("module")
      @Scope(ScopeType.SESSION)
      @Table(name = "adm_modules")
      public class Module implements Serializable
      {
        ...
        @Column(nullable = false, length = 50)
        private String            name;
        ...

        ...
        /**
         * Get the name.
         * @return The name.
         */
        public String getName()
        {
          return name;
        }

        /**
         * Set the name.
         * @param _name The name to set.
         */
        public void setName(String _name)
        {
          name = _name;
        }
        ...
      }

      Xhtml file:

      <!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:a4j="http://richfaces.org/a4j"
          xmlns:c="http://java.sun.com/jsp/jstl/core">

      <p>
        Look ma! This is c:forEach iterating from 1 to 10.<br/>
        <c:forEach var="i" begin="1" end="10" step="1">
          Next number: <c:out value="${i}" />
        </c:forEach>
      </p>

      <p>
        Look ma! This is a4j:repeat using List of Modules.<br/>
        <a4j:repeat var="oneModule" value="#{core_modules}">
          <h:outputText value="Next entry: #{oneModule.name}"/><br/>
        </a4j:repeat>
      </p>

      <p>
        Look ma! This is c:forEach using List of Modules.<br/>
        <c:forEach var="oneModule" items="${navigation.allowedModules}">
          Next entry: <c:out value="${oneModule.name}"/>
        </c:forEach>
      </p>

      </ui:composition>

      Effect:
      Look ma! This is c:forEach iterating from 1 to 10.
      Next number:

      Look ma! This is a4j:repeat using List of Modules.
      Next entry: module.test.moduleName
      Next entry: admin.user.moduleName

      Look ma! This is c:forEach using List of Modules.
      Next entry:

      As you can see, a4j:repeat works in this simple example, but not c:forEach. For sure there are two entries in core_modules. This behaviour is strange: writes "Next entry:" once and thats it. Someone would think that will write nothing or two empty lines with "Next entry:"...

      I want to use these tags to generation of module list in menu with help of rich:dropDownMenu and rich:menuItem. And a4j:repeat does not work with drop down menu (shows only one-pixel dot). From internet i know that drop down menu should work with c:forEach.

      I use SEAM 2.1.0.SP1, JBoss 4.2.3 and Eclipse 3.4.1.