Struts - order of setting properties

J

joe

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.
 
W

Wendy Smoak

joe said:
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...
 
J

joe

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.
 
O

Oscar kind

joe said:
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".
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top