Announcement Announcement Module
Collapse
No announcement yet.
Access to model Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Access to model

    Hi all.

    i need access from a jsp to some params of a list included in a model.

    How can i access for exmple to the size of the list?

    I know how to access the elements in the list but what tag do i have to use to access the params?

    thx

  • #2
    Out of my head: size() in the java.util.List() interface is not a property but a method. Calling methods on objects using EL is only supported in JSTL 1.1, by using the function taglib. See for instance:

    http://java.sun.com/webservices/docs...doc/JSTL8.html

    Comment


    • #3
      I'm facing similar problem! One way..

      Hi,

      I need to get size of a list in model, on a JSP page, as you mentioned!

      Did you figured it out?

      I think one way(may be not the best) is to just put the list size as an request attribute!!

      Please let me know if you figure out better way!

      Thanks,

      Jay

      Comment


      • #4
        If you can't use JSTL 1.1 (for instance because your container does not support JSP 2.0), you should either use scripting, or store the size as a request/page scoped attribute, as you suggested.

        Or upgarde your container ...

        Rgrds, Thomas

        Comment


        • #5
          This is what i want to do: i have a model with images and i want to show them in rows of five images.

          This could be the code in plain Java:

          Code:
          Iterator it = model.getIterator();
          int num = 0;
          while (it.hasNext()) {
          Image image = (Image)it.next();
          if (num % 5 == 0) {
          // NEW ROW 
          <tr><td>....image....</td></tr>
          num = 0;
          &#125;
          else &#123;
          <td>....image....</td>
          num++;
          &#125;
          &#125;
          how can i do that with jstl????

          Comment


          • #6
            I response myself using java without jstl:

            Code:
            <table>
            <% int num = 1 %>
            <tr>
            <c&#58;forEach items="$&#123;model.images&#125;" var="image">
            <% if &#40;num % 5 == 0&#41; &#123; %>
            <td><img ....></td>
            </tr>
            <tr>
            <% &#125; else &#123; %>
            <td><img ....></td>
            <% &#125;
            num++; &>
            </c&#58;forEach>
            </tr>
            </table>

            Comment


            • #7
              http://forum.java.sun.com/thread.jsp...sageID=2793249

              Comment

              Working...
              X