You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Takis Diakoumis <ta...@alphalink.com.au> on 2003/10/07 16:11:05 UTC

form object names, population and processing

hi

i'm using an ActionForm to populate a form and update (or add new) data. i
have a bean object with set/get methods which i add to my extended
ActionForm class with setMyObject and getMyObject. 

i use the above to populate my form which works fine. when using a tag in a
form say for a text field like below:

<html:text property="myObject.myValue">

the correct value is populated within the form and all seems ok. the
problem i'm having is the generated html is as follows:

<input type="text" name="myObject.myValue" value="whatever"/>

this makes it difficult to reference the above field when using javascript
for focusing, client-side validation and so forth since
document.formName.myObject.myValue.focus() for example will not work. the
only way it would work is if the field name was just the myValue portion.
This of course can be achieved by defining a variable using 

<bean:define id="myBean" name="formName" property="myObject"/>

then just referencing the myBean and whatever field within that object in
the html:text tag. 

however, where struts will populate the field using the above method and
making all your fields accessible using client-side bits like javascript,
it does not quite work when processing the form as the extended ActionForm
will not process the myValue named field as this does not exist directly
within the ActionForm. (i hope this is making sense). 

the alternative would be to define all your set/get for your object in the
ActionForm which as far as i can see violates some of the mvc you're trying
to achieve as the ActionForm becomes the model making it difficult to
reference ejb objects and so forth. again, you could replicate the accessor
methods in the ActionForm, but this too appears as a waste of time and
effort - rewriting an object completely.

basically is there any work-around to the above to achieve field names that
client-side code can work with easily whilst still having the ActionForm do
the population and processing work for you?

any suggestions would be greatly appreciated.

thanks

Takis

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org