about struts logic:iterate tag


Web tier: servlets, JSP, Web frameworks: about struts logic:iterate tag

  1. about struts logic:iterate tag (13 messages)

    I want to write a collection to page.
    I use table to present contents of collection.
    But i want to write 4 elements of collection in one row.
    How to use <logic:iterate> to implement it?
    Any suggestion welcome!
    thanks very much!

    Threaded Messages (13)

  2. Hi Jonah,

       I think u have sufficient knowledge about work flow in Struts.
       If u want to print a collection using <logic:iterate> first of alll u need to know the attributes that are used with this tag.

       <logic:iterage> tag has jsp body and supports 9 attributes with it.

       to make a looop for a collection it is sufficient to have attributes.

       those are 1. id
                 2. name
       1. id is the the identification what we are going to use to iterate the collection that is specified in the 'name' attribute.
      2. name is the name of the collection that we want to iterate.

        First of alll u need to set the collectiin object(name), which u want to iterete, in one of the scopes Viz. page, session, request, application.

       And then u can accessa the collection object using its name in name attribute.
          ArrayList a;
          .........//some code may be here.
          HttpSession session=request.getSession();
          ........ //some code may be here.

      in the jsp page u need to mention like this

         <logic:iterage id="maruref" name"maru">
              <TD><bean:write name="maruref" property="property name "></TD>

       Here property name is the property name object 'a' for first enty
     when the loop iterates again it prients the propertis of next entriens(next object in a) of 'a'

        <bean:write name..../> tag us used to write the approprite property of the collectio object in the page

        reply me still any doubt....
        I will try....

    best of luck.


  3. First of all,thanks you reply.
    You didn't uderstand my question.Maybe I didn't represented myself correctly.
    For example:I have a collection that has 8 elements.I want to represent them like follow.
    element1 element2 element3 element4
    element5 element6 element7 element8
    In here element(i) indicate the properties of element I want to represent.
    In other words,I want to represent more than one element of collection in only one row of table.
    Following what you said,I could only represent one element of collection in one row of table.
    I wish I could represent myself correctly this time.
    Thanks a lot.
  4. Use the iterate tags "indexId" attribute to store the index count in a page context variable. Whenever the index is evenly divisibly by 4, insert a new table-row tag.

    <logic:iterate id="identification" name="collecitonobject" indexId="counter">
  5. Thank you very much!!!
    I got it.
  6. If I want to write more than two rows,how to do?
    Each row represent more than one elements.
  7. More than two rows[ Go to top ]

    I am not sure what you mean. Do you mean this?

    element1 element2 element3 element4
    element5 element6 element7 element8
    element9 element10 element11 element12

    If so, insert a <tr> tag every time the counter is evenly divible by 4 (counter % 4 == 0).
  8. More than two rows[ Go to top ]

    Yes,it is exactly my means.
    Coulud give me a simple example about how to write such tag using
  9. More than two rows[ Go to top ]

    Unfortunately, the logic tags of Struts are limited, and can't handle this kind of computation. To do something like this, you would need some kind of expression language. For example, JSTL supports this kind of thing nicely, and would be a better option if your server supports servlet 2.3+.

    Of course, you can always fall back to scripting, which works no matter what:

    <logic:iterate id="identification" name="collectionobject" indexId="counter">
    Integer counter = (Integer) pageContext.getAttribute("counter");
    /* Begin row if divisible by 1 */
    if (counter.intValue() % 4 == 1) { %>

    <% } %>
    <td>[print element]</td>

    Technically, this is not 100% correct, because I am not generating the closing </tr> tag, but the browser should render things correctly anyway, and I don't feel like grinding out all the logic.
  10. Fix the header.[ Go to top ]

    Hi Maru.Your post here is helpful to everyone no doubt.Thanks. I regularly use logic:iterate in my application.But,the problem is the Header of the table is not being fixed that I require very much. Waiting for your tips. With Regards.... ~Deep.
  11. [ Go to top ]

    I have set a arraylisi in a property of bean, den i want to show these values with checkboxes in a row. how can i do this?
  12. about struts logic:iterate tag[ Go to top ]

    Hi, I had used struts logic iterate tag and arraylist to display items in a dropdown list. Here is code: <html:select property="name" >
                                <logic:iterate id="emp" name="emplist">
                                    <html:option value="${emp}">${emp}</html:option>

     </html:select>.                                                                                                                         I hope that helps you. If you had doubts regarding this code, kindly let me know.

  13. query[ Go to top ]

    How can i apply condition on number of iterations of<logic:iterator> tag without using scriplet.

  14. question[ Go to top ]

    How can i apply condition on number of iterations of <logic:iterator> tag