Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Struts - order of setting properties

Reply
Thread Tools

Struts - order of setting properties

 
 
joe
Guest
Posts: n/a
 
      03-31-2005
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.
 
Reply With Quote
 
 
 
 
Wendy Smoak
Guest
Posts: n/a
 
      03-31-2005
"joe" <(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
 
joe
Guest
Posts: n/a
 
      04-01-2005
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.
 
Reply With Quote
 
Oscar kind
Guest
Posts: n/a
 
      04-01-2005
joe <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting properties (not necessarily "Properties") in Java 5.0 Wardie Java 4 11-08-2006 09:46 AM
Is it safe to point to Internet for locating struts DTD files in struts TLDs and XML files? Katie Wright Java 8 01-07-2005 03:37 PM
[Struts]output javascript in struts perform() sin Java 3 02-22-2004 08:27 AM
Integrate a Struts app with a non-struts app jc1771 Java 0 12-28-2003 06:36 PM
Struts Installation - missing struts.tld??? Jason Us Java 0 10-03-2003 11:36 PM



Advertisments