Java

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Iterate over list in in list in form bean.

    27 answers - 471 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    From: "Jrg Eichhorn" <eichhorn (AT) ponton-consulting (DOT) de>
    i have a form bean with a list property of complex object which also
    contains a list of objects. When iterating over the first list and using
    indexed elements, then values of the first list are transferred back when
    submitting the form. The values of the inner list is displayed correctly
    but is not transmitted back on submit.
    I think you need to use the nested taglib for this:
  • No.1 | | 2062 bytes | |

    Wendy Smoak wrote the following on 7/12/2005 7:12 PM:
    From: "Jrg Eichhorn" <eichhorn (AT) ponton-consulting (DOT) de>

    >>i have a form bean with a list property of complex object which also
    >>contains a list of objects. When iterating over the first list and using
    >>indexed elements, then values of the first list are transferred back when
    >>submitting the form. The values of the inner list is displayed correctly
    >>but is not transmitted back on submit.


    I think you need to use the nested taglib for this:

    You can do this without using the nested tags, but the nested tags make
    it much cleaner. Here's an example from a demo app that I keep meaning
    to post to show how it can be done using either the nested or regular
    JSTL tags

    Company has divisions and in each division there is a list of
    departments with names.

    <%-- JSTL way --%>

    <c:forEach items="${companyForm.divisions}" var="division"
    varStatus="divstatus">
    Division: <html:text property="divisions[${divstatus.index}].name"
    value="${division.name}" /><br>
    <c:forEach items="${division.departments}" var="department"
    varStatus="depstatus">
    Department: <html:text
    property="divisions[${divstatus.index}].departments[${depstatus.index}].name"
    value="${department.name}" /><br>
    </c:forEach>
    </c:forEach>

    <%-- Nested tag way --%>

    <nested:root name="companyForm">
    <nested:iterate property="divisions">
    Division: <nested:text property="name" /><br>
    <nested:iterate property="departments">
    Department: <nested:text property="name" /><br>
    </nested:iterate>
    </nested:iterate>
    </nested:root>

    To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
  • No.2 | | 446 bytes | |

    From: "Rick Reumann" <struttin (AT) reumann (DOT) net>

    Here's an example from a demo app that I keep meaning
    to post to show how it can be done using either the nested or regular
    JSTL tags

    Please do! Showing side by side examples from
    Struts "classic",
    Struts-EL + JSTL 1.0, and
    Struts + JSP 2.0 + JSTL 1.1
    is on my TD list, and I'm sure you've done a much better job of it than I
    could.
  • No.3 | | 785 bytes | |

    7/12/05, Wendy Smoak <java (AT) wendysmoak (DOT) comwrote:
    From: "Rick Reumann" <struttin (AT) reumann (DOT) net>

    Here's an example from a demo app that I keep meaning
    to post to show how it can be done using either the nested or regular
    JSTL tags

    Please do! Showing side by side examples from
    Struts "classic",
    Struts-EL + JSTL 1.0, and
    Struts + JSP 2.0 + JSTL 1.1
    is on my TD list, and I'm sure you've done a much better job of it than I
    could.

    Does the above mean that "Struts + JSP 1.2 + JSTL 1.0" (no Struts-EL)
    is not possible?

    Michael.

    To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
  • No.4 | | 1620 bytes | |

    Wendy Smoak wrote the following on 7/12/2005 7:48 PM:
    From: "Rick Reumann" <struttin (AT) reumann (DOT) net>

    >Here's an example from a demo app that I keep meaning
    >>to post to show how it can be done using either the nested or regular
    >>JSTL tags


    Please do! Showing side by side examples from
    Struts "classic",
    Struts-EL + JSTL 1.0, and
    Struts + JSP 2.0 + JSTL 1.1

    Well I sort of did most the part that you'd be concerned with:) The rest
    of the demo deals with dealing with the Lists to not get
    Bounds etc problem is so many different ways to deal with it.

    <%-- JSTL way --%>

    <c:forEach items="${companyForm.divisions}" var="division"
    varStatus="divstatus">
    Division: <html:text property="divisions[${divstatus.index}].name"
    value="${division.name}" /><br>
    <c:forEach items="${division.departments}" var="department"
    varStatus="depstatus">
    Department: <html:text
    property="divisions[${divstatus.index}].departments[${depstatus.index}].name"
    value="${department.name}" /><br>
    </c:forEach>
    </c:forEach>

    <%-- Nested tag way --%>

    <nested:root name="companyForm">
    <nested:iterate property="divisions">
    Division: <nested:text property="name" /><br>
    <nested:iterate property="departments">
    Department: <nested:text property="name" /><br>
    </nested:iterate>
    </nested:iterate>
    </nested:root>
  • No.5 | | 239 bytes | |

    Michael Jouravlev wrote:
    Does the above mean that "Struts + JSP 1.2 + JSTL 1.0" (no Struts-EL)
    is not possible?
    I don't know about 'possible' but JSP 1.2 includes JSTL 1.1, so why would
    you want to?
    L.
  • No.6 | | 1384 bytes | |

    Jrg
    Hard to answer a reference to a previous posting when the previous posting
    was erased
    It would help if you would include previous posts from thread when replying

    More specifically if there is information from a previous post which you are
    referencing it is best practice to include in the referenced info
    Vielen Danke,
    Martin
    Message
    From: "Jrg Eichhorn" <eichhorn (AT) ponton-consulting (DOT) de>
    To: "Struts Users Mailing List" <user (AT) struts (DOT) apache.org>
    Sent: Wednesday, July 13, 2005 4:47 AM
    Subject: Re: Iterate over list in in list in form bean.

    Hello,

    thanks for the hint and example. I've choosen the nested way to do this,
    because i
    think this makes the jsp code more readable.

    I there a way to do the same using request scope?
    When i do this i get an exception because the collection is not re-filled
    anymore.
    In my previous example the first collection was recreated via the
    getCollection(int index) method.

    Thanks again.

    Jrg Eichhorn

    To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org

    To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
  • No.7 | | 786 bytes | |

    7/12/05, Laurie Harper <laurie (AT) holoweb (DOT) netwrote:
    Michael Jouravlev wrote:
    Does the above mean that "Struts + JSP 1.2 + JSTL 1.0" (no Struts-EL)
    is not possible?

    I don't know about 'possible' but JSP 1.2 includes JSTL 1.1, so why would
    you want to?

    "Standard-1.1 (JSTL 1.1) requires a JSP container that supports the
    Java Servlet 2.4 and JavaServer Pages 2.0 specifications.

    Standard-1.0 (implementation of the JSTL 1.0 specification) requires a
    JSP container that supports the Java Servlet 2.3 and JavaServer Pages
    1.2 specifications."

    Michael.

    To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
  • No.8 | | 855 bytes | |

    From: "Michael Jouravlev" <jmikus (AT) gmail (DOT) com>

    >Showing side by side examples from
    >Struts "classic",
    >Struts-EL + JSTL 1.0, and
    >Struts + JSP 2.0 + JSTL 1.1
    >is on my TD list


    Does the above mean that "Struts + JSP 1.2 + JSTL 1.0" (no Struts-EL)
    is not possible?

    (Is this a trick question?) Sure, it's possible. It's going to make some
    things harder than they need to be, such as

    <c:forEach items="${accountForm.map['accounts']}" var="acct" >
    <html-el:multibox property="accounts" value="${acct}"/>
    </c:forEach>

    And using Struts-EL will force you into the recommended practice of using
    the JSTL tags whenever possible, because the Struts tags with JSTL
    equivalents were intentionally left out.
  • No.9 | | 844 bytes | |

    Michael Jouravlev wrote:

    7/12/05, Laurie Harper <laurie (AT) holoweb (DOT) netwrote:

    >>Michael Jouravlev wrote:
    >>

    Does the above mean that "Struts + JSP 1.2 + JSTL 1.0" (no Struts-EL)
    is not possible?
    >>
    >>I don't know about 'possible' but JSP 1.2 includes JSTL 1.1, so why would
    >>you want to?


    "Standard-1.1 (JSTL 1.1) requires a JSP container that supports the
    Java Servlet 2.4 and JavaServer Pages 2.0 specifications.

    Standard-1.0 (implementation of the JSTL 1.0 specification) requires a
    JSP container that supports the Java Servlet 2.3 and JavaServer Pages
    1.2 specifications."

    Michael.

    , I mis-read 1.2 as 2.0! Doh
  • No.10 | | 1376 bytes | |

    7/13/05, Wendy Smoak <java (AT) wendysmoak (DOT) comwrote:
    From: "Michael Jouravlev" <jmikus (AT) gmail (DOT) com>

    >Showing side by side examples from
    >Struts "classic",
    >Struts-EL + JSTL 1.0, and
    >Struts + JSP 2.0 + JSTL 1.1
    >is on my TD list


    Does the above mean that "Struts + JSP 1.2 + JSTL 1.0" (no Struts-EL)
    is not possible?

    (Is this a trick question?)

    No, it is not a trick question. I just started with JSTL. I used only
    Struts tags before.

    Sure, it's possible. It's going to make some
    things harder than they need to be, such as

    <c:forEach items="${accountForm.map['accounts']}" var="acct" >
    <html-el:multibox property="accounts" value="${acct}"/>
    </c:forEach>

    And using Struts-EL will force you into the recommended practice of using
    the JSTL tags whenever possible, because the Struts tags with JSTL
    equivalents were intentionally left out.

    <html-elis Struts-EL tag, is not it? I would prefer to use JSTL
    only. I think I can do that. But it this case, what Struts-EL is for?
    For convenience only?

    Michael.

    To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
  • No.11 | | 832 bytes | |

    From: "Michael Jouravlev" <jmikus (AT) gmail (DOT) com>

    <c:forEach items="${accountForm.map['accounts']}" var="acct" >
    <html-el:multibox property="accounts" value="${acct}"/>
    </c:forEach>

    <html-elis Struts-EL tag, is not it? I would prefer to use JSTL
    only. I think I can do that. But it this case, what Struts-EL is for?
    For convenience only?

    Struts-EL gives you the ability to use expressions in the Struts tags. I
    think it's more than a convenience for example, how would you rewrite the
    code above if you could not use an expression in the 'value' attribute?

    I'm as resistant as anyone to adding Yet Another Taglib to a project, but
    this one is just a subset of the original Struts tags, modified to accept
    expressions.
  • No.12 | | 404 bytes | |

    Wendy Smoak wrote the following on 7/13/2005 6:14 PM:

    Struts-EL gives you the ability to use expressions in the Struts tags. I
    think it's more than a convenience for example, how would you rewrite the
    code above if you could not use an expression in the 'value' attribute?

    Struts-EL tags are a must if you aren't on JSP 2.0. No debating this -
    Discussion over:)
  • No.13 | | 773 bytes | |

    7/13/05, Rick Reumann <struttin (AT) reumann (DOT) netwrote:
    Wendy Smoak wrote the following on 7/13/2005 6:14 PM:

    Struts-EL gives you the ability to use expressions in the Struts tags. I
    think it's more than a convenience for example, how would you rewrite the
    code above if you could not use an expression in the 'value' attribute?

    Struts-EL tags are a must if you aren't on JSP 2.0. No debating this -
    Discussion over:)

    Would you care to point to explanation? ;) I want to abandon struts
    tags completely, so I am really interested.

    Michael.

    To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
  • No.14 | | 662 bytes | |

    7/13/05, Leon Rosenberg <struts_user (AT) anotheria (DOT) netwrote:
    It's not Friday, but I'd like to now what you need the JSTL tags for? What
    is it, what you can't do with standart (struts without EL) tags? What do you
    need EL for?

    Regards
    Leon :-)

    How about "I want to fork Struts into StrutsWorks, and I want to take
    only the most essential part of it, so no one would accuse me in
    stealing and putting my name on other's stuff"?

    :-)

    To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
  • No.15 | | 1669 bytes | |

    7/13/05, J Eichhorn <eichhorn (AT) ponton-consulting (DOT) dewrote:

    thanks for the hint and example. I've choosen the nested way to do this,
    because i
    think this makes the jsp code more readable.

    I there a way to do the same using request scope?
    When i do this i get an exception because the collection is not re-filled
    anymore.

    This is the same question I have, but of course I'm a week late in
    asking it. However, I noticed that no one answered J's version so
    I'll ask it again:

    Is there a way to do the same using request scope?

    I've been beating my head against this all weekend to no avail. I
    understand how to do this in session scope, but don't know if it's
    even possible in request scope.

    As I understand things (which may be wrong), when the form is
    submitted (in request scope) a new form bean is created and populated
    with the values in the collection from the HTML form. But, of course,
    a newly created form won't know how many elements are in the form so
    it can't pre-populate the collection with beans to be filled in.
    Right? So following this path leads to wailing, lamentation, gnashing
    of teeth, rending of clothes and utter frustration. Right?

    If there is simply no way to do this, I'd really appreciate someone
    letting me know so that I'm put out of my misery. And, if someone
    could suggest a workaround, I'd be most welcome.

    To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
  • No.16 | | 1864 bytes | |

    There are ways to resolve this, see this page on the wiki

    Niall

    Message
    From: "Mike Elliott" <hbrednek (AT) gmail (DOT) com>
    Sent: Monday, July 18, 2005 3:55 PM

    7/13/05, J Eichhorn <eichhorn (AT) ponton-consulting (DOT) dewrote:

    thanks for the hint and example. I've choosen the nested way to do this,
    because i
    think this makes the jsp code more readable.

    I there a way to do the same using request scope?
    When i do this i get an exception because the collection is not re-filled
    anymore.

    This is the same question I have, but of course I'm a week late in
    asking it. However, I noticed that no one answered J's version so
    I'll ask it again:

    Is there a way to do the same using request scope?

    I've been beating my head against this all weekend to no avail. I
    understand how to do this in session scope, but don't know if it's
    even possible in request scope.

    As I understand things (which may be wrong), when the form is
    submitted (in request scope) a new form bean is created and populated
    with the values in the collection from the HTML form. But, of course,
    a newly created form won't know how many elements are in the form so
    it can't pre-populate the collection with beans to be filled in.
    Right? So following this path leads to wailing, lamentation, gnashing
    of teeth, rending of clothes and utter frustration. Right?

    If there is simply no way to do this, I'd really appreciate someone
    letting me know so that I'm put out of my misery. And, if someone
    could suggest a workaround, I'd be most welcome.

    To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
  • No.17 | | 2394 bytes | |

    Good Morning Mike
    There are a Number of options for implementing with request scope and manual
    validation explained by Rick Reumann

    I think its worth noting what Thomas Edison said of weekend warriors
    "I have not failed. I've just found 10,000 ways that won't work."-- Thomas
    Edison

    Message
    From: "Mike Elliott" <hbrednek (AT) gmail (DOT) com>
    To: "Struts Users Mailing List" <user (AT) struts (DOT) apache.org>
    Sent: Monday, July 18, 2005 10:55 AM
    Subject: Re: Iterate over list in in list in form bean.

    7/13/05, J Eichhorn <eichhorn (AT) ponton-consulting (DOT) dewrote:

    thanks for the hint and example. I've choosen the nested way to do this,
    because i
    think this makes the jsp code more readable.

    I there a way to do the same using request scope?
    When i do this i get an exception because the collection is not re-filled
    anymore.

    This is the same question I have, but of course I'm a week late in
    asking it. However, I noticed that no one answered J's version so
    I'll ask it again:

    Is there a way to do the same using request scope?

    I've been beating my head against this all weekend to no avail. I
    understand how to do this in session scope, but don't know if it's
    even possible in request scope.

    As I understand things (which may be wrong), when the form is
    submitted (in request scope) a new form bean is created and populated
    with the values in the collection from the HTML form. But, of course,
    a newly created form won't know how many elements are in the form so
    it can't pre-populate the collection with beans to be filled in.
    Right? So following this path leads to wailing, lamentation, gnashing
    of teeth, rending of clothes and utter frustration. Right?

    If there is simply no way to do this, I'd really appreciate someone
    letting me know so that I'm put out of my misery. And, if someone
    could suggest a workaround, I'd be most welcome.

    To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org

    To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
  • No.18 | | 2109 bytes | |

    Mike Elliott wrote the following on 7/18/2005 10:55 AM:

    I've been beating my head against this all weekend to no avail. I
    understand how to do this in session scope, but don't know if it's
    even possible in request scope.

    As I understand things (which may be wrong), when the form is
    submitted (in request scope) a new form bean is created and populated
    with the values in the collection from the HTML form. But, of course,
    a newly created form won't know how many elements are in the form so
    it can't pre-populate the collection with beans to be filled in.
    Right?

    I'm still not totally clear where the problem is, since I'm not sure
    what Session has to do with the initial setup of the form. It might help
    if you let us know what the exact problem is when using request scope

    1) A problem when you submit the form and getting 'index' problems
    showing up in the logs?

    2) Is it making sure the nested structure is still there when validation
    fails?

    I'm confused because you mention "But, of course, a newly created form
    won't know how many elements are in the form so it can't pre-populate
    the collection with beans to be filled in." This statement confused me
    because you seem to be implying it works when it's in Session which
    doesn't make sense since even with a Session scoped form you still need
    to some initial population somewhere.

    Typically I feel you should always go to some sort of "setUp" action or
    dispatch method BEFRE you ever forward to a form. Initially you can
    often skip this step but later on there will be something you want to
    'do' before you get to the form anyway so I find it good practice to go
    to a 'set up' first.

    For the two problems listed above the link Naill posted is good
    (and I just recently
    added to that link the way I like to do it).

    Let us know if you can't get it to work. I have to use Nested stuff all
    the time, so I'll be able to help.
  • No.19 | | 2657 bytes | |

    I've stumbled across a similar problem that I'm trying to find the
    Struts solution for.

    I have a form which allows users to add a dynamic amount of rows (via
    a button that says "Add Row") and then submit the form with as little
    or many rows as they wish. Can a form bean be setup using collections
    instead of other object types? What is the proper way to handle a
    dynamic amount of the same data coming in to a Action?

    ~ Andrew Tomaka

    7/18/05, Rick Reumann <struttin (AT) reumann (DOT) netwrote:
    Mike Elliott wrote the following on 7/18/2005 10:55 AM:

    I've been beating my head against this all weekend to no avail. I
    understand how to do this in session scope, but don't know if it's
    even possible in request scope.

    As I understand things (which may be wrong), when the form is
    submitted (in request scope) a new form bean is created and populated
    with the values in the collection from the HTML form. But, of course,
    a newly created form won't know how many elements are in the form so
    it can't pre-populate the collection with beans to be filled in.
    Right?

    I'm still not totally clear where the problem is, since I'm not sure
    what Session has to do with the initial setup of the form. It might help
    if you let us know what the exact problem is when using request scope

    1) A problem when you submit the form and getting 'index' problems
    showing up in the logs?

    2) Is it making sure the nested structure is still there when validation
    fails?

    I'm confused because you mention "But, of course, a newly created form
    won't know how many elements are in the form so it can't pre-populate
    the collection with beans to be filled in." This statement confused me
    because you seem to be implying it works when it's in Session which
    doesn't make sense since even with a Session scoped form you still need
    to some initial population somewhere.

    Typically I feel you should always go to some sort of "setUp" action or
    dispatch method BEFRE you ever forward to a form. Initially you can
    often skip this step but later on there will be something you want to
    'do' before you get to the form anyway so I find it good practice to go
    to a 'set up' first.

    For the two problems listed above the link Naill posted is good
    (and I just recently
    added to that link the way I like to do it).

    Let us know if you can't get it to work. I have to use Nested stuff all
    the time, so I'll be able to help.
  • No.20 | | 1409 bytes | |

    Andrew Tomaka wrote the following on 7/18/2005 2:13 PM:

    I have a form which allows users to add a dynamic amount of rows (via
    a button that says "Add Row") and then submit the form with as little
    or many rows as they wish. Can a form bean be setup using collections
    instead of other object types? What is the proper way to handle a
    dynamic amount of the same data coming in to a Action?

    I think to set this up where the user can add as many as they wish
    you'll have to do some DHTML stuff where you will be writing out the new
    elements using javascript. You'll probably have to keep track of what's
    in the currentDiv and append to it when they click "add new"

    You'll need a counter of the 'currentIndex' and you'll end up writing
    javascript to write to a div that will make the elements like

    write( currentDivContents + "<br/><html:text
    propety='yourList["+curIndex+"].firstName'/>");

    course make sure for your "yourList" that you use an approach like

    An easier approach might be to only allow them to enter a fixed amount
    at a time, say five or so. After they submit they could enter more. This
    would cut down on the amount of javascript.

    And yes in either scenario you set up your ActionForm to use a property
    of type List that would hold your Collection of beans.
  • No.21 | | 3605 bytes | |

    7/18/05, Rick Reumann <struttin (AT) reumann (DOT) netwrote:

    I'm still not totally clear where the problem is, since I'm not sure
    what Session has to do with the initial setup of the form.

    The difference is unobvious, I admit, but this is what I was thinking
    of: If I use a session bean, I can do some sort of setup (from an
    Action) on its initial creation, including creating the list of
    contained objects. That can't happen if it's in request scope because
    there is no chance to invoke the setup before the bean is populated
    from the request.

    1) A problem when you submit the form and getting 'index' problems
    showing up in the logs?

    More than showing up, the submit was trying to populate the bean with
    indexed properties but the list containing the indexed properties was
    of size zero. The
    answer to the problem was given by the previous posters. Thanks guys.

    What made the difference was the Wiki page section (BeanUtils Indexed
    Properties Issue) pointing out that there is a bug in JDK 1.4 which
    prevents the solution of writing your own getXXX( int ndx ) property.
    I had done that (in desperation) and when that didn't work either, I
    threw up my hands and wrote the list. I felt that it _should_ have
    worked and when it didn't I just assumed my understanding of the
    situation was inadequate and gave up. I'm delighted to find out that
    the problem is in the implementation and not in my mental picture of
    how this whole thing works.

    I'm confused because you mention "But, of course, a newly created form
    won't know how many elements are in the form so it can't pre-populate
    the collection with beans to be filled in." This statement confused me
    because you seem to be implying it works when it's in Session which
    doesn't make sense since even with a Session scoped form you still need
    to some initial population somewhere.

    But you can do that once, before all this other stuff takes place. I
    realize that wasn't an obvious inference but that's what I meant.

    Typically I feel you should always go to some sort of "setUp" action or
    dispatch method BEFRE you ever forward to a form.

    But doesn't that go away in request scope when the form is submitted
    back to the Action? Doesn't a new form get created and populated from
    the HTML? It sure looks like that's what's happening to me.

    For the two problems listed above the link Naill posted is good
    (and I just recently
    added to that link the way I like to do it).

    I came up with another solution which might be worthy of
    consideration. Instead of using arrays, extend a list with the
    desired get( int ) method and use that list instead:

    public class SkillActionForm extends ActionForm {

    protected List skills = new LazyArrayList();

    public class LazyArrayList extends ArrayList {
    public get( int index ) {
    while (size() <= index) add( new SkillBean() );
    return super.get( index );
    }
    }
    }

    This is the solution I eventually adopted (successfully) but I have a
    fondness for nested classes which others may not share.

    Anyway, thanks to all, I've gotten past the problem with an increased
    understanding of the intricacies of this here Struts stuff.

    To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
  • No.22 | | 808 bytes | |

    Mike Elliott wrote the following on 7/18/2005 3:18 PM:

    I came up with another solution which might be worthy of
    consideration. Instead of using arrays, extend a list with the
    desired get( int ) method and use that list instead:

    public class SkillActionForm extends ActionForm {

    protected List skills = new LazyArrayList();

    public class LazyArrayList extends ArrayList {
    public get( int index ) {
    while (size() <= index) add( new SkillBean() );
    return super.get( index );
    }
    }
    }

    This is the solution I eventually adopted (successfully) but I have a
    fondness for nested classes which others may not share.

    I'm pretty sure what LazyList is doing similar stuff in the background,
    so I'm curious why you don't just use that?
  • No.23 | | 822 bytes | |

    7/18/05, Mike Elliott <hbrednek (AT) gmail (DOT) comwrote:
    If I use a session bean, I can do some sort of setup (from an
    Action) on its initial creation, including creating the list of
    contained objects. That can't happen if it's in request scope because
    there is no chance to invoke the setup before the bean is populated
    from the request.

    ActionForm.reset() for session-scoped forms, ActionForm.ActionForm()
    for request-scoped forms. I do not remeber, if reset() is called for
    request-scoped forms.

    Why would you want to use request scope anyway? I use session scope
    and I am pretty happy.

    Michael.

    To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
  • No.24 | | 1535 bytes | |

    Michael Jouravlev wrote the following on 7/18/2005 3:59 PM:

    ActionForm.reset() for session-scoped forms, ActionForm.ActionForm()
    for request-scoped forms. I do not remeber, if reset() is called for
    request-scoped forms.

    Yes, reset is always called when the form submits. I know I mentioned in
    this in another post but I would disagree with repopulating your beans
    in the reset() UNLESS you did adopt the whole ball of wax the way you
    have designed your stuff Michael. In other words if you go with your
    approach of the form beans doing other stuff than holding user input,
    than you can go ahead and mess with the reset doing that kind of stuff,
    but if Mike is sticking to 'typical' Struts than I wouldn't recommend
    repopulating in the reset.

    Why would you want to use request scope anyway? I use session scope
    and I am pretty happy.

    Well I could see for large forms with nested data it might not be a
    great idea to keep these around in the Session. I 'try' to stick to
    using the Request when I can but I don't bend over backwards like
    some do on this list to avoid the Session I'm in "The Session is your
    friend" camp:). Request will work fine however for Mike's situation. He
    just needs to wrap his collection in his ActionForm around a LazyList
    (or he can use a regular list and do the handcranking approach of
    incrementing the size when needed in the getList property in his form.
    LazyList is cleaner, though).
  • No.25 | | 1453 bytes | |

    7/18/05, Rick Reumann <struttin (AT) reumann (DOT) netwrote:
    Michael Jouravlev wrote the following on 7/18/2005 3:59 PM:

    ActionForm.reset() for session-scoped forms, ActionForm.ActionForm()
    for request-scoped forms. I do not remeber, if reset() is called for
    request-scoped forms.

    Yes, reset is always called when the form submits. I know I mentioned in
    this in another post but I would disagree with repopulating your beans
    in the reset() UNLESS you did adopt the whole ball of wax the way you
    have designed your stuff Michael. In other words if you go with your
    approach of the form beans doing other stuff than holding user input,
    than you can go ahead and mess with the reset doing that kind of stuff,
    but if Mike is sticking to 'typical' Struts than I wouldn't recommend
    repopulating in the reset.

    'Typical' is not always better. I am finishing rewriting Mail Reader
    using my approach, and it looks much cleaner, at least to me ;) and is
    more robust. I understand that having session objects opens a whole
    can of worms related to garbage-collecting of abandoned objects, and
    Struts does not have this facility. I saw a project which does just
    that, but cannot find it now ;(

    Michael.

    To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
  • No.26 | | 1399 bytes | |

    Well I could see for large forms with nested data it might not be a
    great idea to keep these around in the Session. I 'try' to stick to
    using the Request when I can but I don't bend over backwards like
    some do on this list to avoid the Session I'm in "The Session is your
    friend" camp:). Request will work fine however for Mike's situation. He
    just needs to wrap his collection in his ActionForm around a LazyList
    (or he can use a regular list and do the handcranking approach of
    incrementing the size when needed in the getList property in his form.
    LazyList is cleaner, though).

    Request is required for my situation -- the user can have multiple
    versions of the same page active in the same session. That's what
    drove me away from the 'working' session scope bean -- I had users who
    were messing up the session scoped bean by opening the same page
    multiple times and making modifications.

    I don't see LazyList as any cleaner. You have to add one method in
    either case. With LazyList you have to implement Factory then add the
    create() method. Extending ArrayList you have to implement a new
    get(). I'll stick with the latter.

    To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
  • No.27 | | 1355 bytes | |

    7/18/05, Mike Elliott <hbrednek (AT) gmail (DOT) comwrote:
    Well I could see for large forms with nested data it might not be a
    great idea to keep these around in the Session. I 'try' to stick to
    using the Request when I can but I don't bend over backwards like
    some do on this list to avoid the Session I'm in "The Session is your
    friend" camp:). Request will work fine however for Mike's situation. He
    just needs to wrap his collection in his ActionForm around a LazyList
    (or he can use a regular list and do the handcranking approach of
    incrementing the size when needed in the getList property in his form.
    LazyList is cleaner, though).

    Request is required for my situation -- the user can have multiple
    versions of the same page active in the same session. That's what
    drove me away from the 'working' session scope bean -- I had users who
    were messing up the session scoped bean by opening the same page
    multiple times and making modifications.

    Wicket has versioning for situations like this. I am thinking, does it
    make sense to create versioned action forms for Struts?

    Michael.

    To unsubscribe, e-mail: user-unsubscribe (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org

Re: Iterate over list in in list in form bean.


max 4000 letters.
Your nickname that display:
In order to stop the spam: 7 + 6 =
QUESTION ON "Java"

EMSDN.COM