Struts - order of setting properties

Discussion in 'Java' started by joe, Mar 31, 2005.

  1. joe

    joe Guest

    With regard to struts; anyone know in what determines the order for
    getters and setters being executed on a form?

    I'm looking at a problem on a existing form where adding a field
    upsets the order by which values are being set (in this case some
    values rely on one particular value being set first - ie an index).

    I want to either amend the order in which the setters are executed or
    if it based on a convention (eg naming) then look at changing the
    properties.

    Thanks in Advance.
    joe, Mar 31, 2005
    #1
    1. Advertising

  2. joe

    Wendy Smoak Guest

    "joe" <> wrote:
    > With regard to struts; anyone know in what determines the order for
    > getters and setters being executed on a form?
    >
    > I'm looking at a problem on a existing form where adding a field
    > upsets the order by which values are being set (in this case some
    > values rely on one particular value being set first - ie an index).
    >
    > I want to either amend the order in which the setters are executed or
    > if it based on a convention (eg naming) then look at changing the
    > properties.


    If you're talking about form bean population, when the form is submitted and
    Struts calls setWhatever(...) for each property...

    It more than likely does it in whatever order the parameters appear in the
    request. And that order is usually the order they appear in the form itself
    (the HTML, not visually,) *but* you can't depend on it. AFAIK, the order of
    parameters isn't defined in the HTML specification-- some browser could
    decide to do them alphabetically, or in reverse, and that would be fine.

    So I think you're going to need to look at your design. It might be as
    simple as a bit of JavaScript to modify the form before it gets submitted.
    Post an example if you want advice...

    --
    Wendy
    Wendy Smoak, Mar 31, 2005
    #2
    1. Advertising

  3. joe

    joe Guest

    Here is an example of what I'm doing:

    JSP Code:

    <html:form action="/editTRPAApprover">
    <html:hidden property="xIndex"/>
    <table cellspacing="0" width="100%">
    <tr>
    <td><html:text property="propertyA"/></td>
    <td><html:text property="propertyB"/></td>
    <td><html:text property="propertyC"/></td>


    JAVA Form Code:

    protected int xIndex;

    public void setXIndex(int xIndex) {
    this.xIndex = xIndex;
    }

    public int getXIndex() {
    return xIndex;
    }

    public Object getPropertyA() {
    return xxx;
    }

    public void setPropertyA(Object value) {
    do xxx;
    }

    public Object getPropertyB( ...

    -----------

    Basically, xIndex needs to be set first as all the other properties
    use the index value. However in my code, as I add more properties,
    some of the new setters get executed before the setXIndex() method.

    Of course I could store the index elsewhere (eg in the session) but I
    am maintaining an existing application and that would making changes
    in many different places.

    I would like to force the setXIndex() method to be executed first
    (even if it mean renaming some of the property names) before any of
    the other properties if it is at all possible.

    Thanks for you help.
    joe, Apr 1, 2005
    #3
  4. joe

    Oscar kind Guest

    joe <> wrote:
    >
    > Basically, xIndex needs to be set first as all the other properties
    > use the index value. However in my code, as I add more properties,
    > some of the new setters get executed before the setXIndex() method.


    Then why not use indexed properties? Or mapped properties if the index is
    a String? The struts documentation on the website explains how.

    You may want to pay extra attention to the sections "Dynamic Indexes for
    Indexed Properties" and "Indexed Tags".


    --
    Oscar Kind http://home.hccnet.nl/okind/
    Software Developer for contact information, see website

    PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
    Oscar kind, Apr 1, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Katie Wright
    Replies:
    8
    Views:
    4,205
    Andrea Desole
    Jan 7, 2005
  2. Jason Us
    Replies:
    0
    Views:
    970
    Jason Us
    Oct 4, 2003
  3. jc1771
    Replies:
    0
    Views:
    390
    jc1771
    Dec 28, 2003
  4. sin
    Replies:
    3
    Views:
    711
    Sudsy
    Feb 22, 2004
  5. Wardie
    Replies:
    4
    Views:
    482
    Wardie
    Nov 8, 2006
Loading...

Share This Page