wood burning stoves*
The moose likes Struts and the fly likes how to specify composite data in s struts FORM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to specify composite data in s struts FORM" Watch "how to specify composite data in s struts FORM" New topic
Author

how to specify composite data in s struts FORM

ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 374
In the FORM, there is a variable like --

public class MyForm extends ActionForm {

private Address addr;
..
}

Address is a class like --

public class Address {

private String city;
private String state;
....
}


In my jsp, I want to specify city, can I do

...value='${MyForm.addr.city}'...

Similarly, can I do

...="javascript:myscript(MyForm.addr.city)" ?

i.e.

can I specify city by "MyForm.addr.city" ?? any restriction on this ?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Originally posted by ben oliver:
can I do

...value='${MyForm.addr.city}'...

Yes, you can. You can go as many levels deep as you want. The only warning I would give is that if you put these objects in request scope and then redisplay the page for a validation error, that whole complicated structure you've built will be gone and you have to build it all over again before redisplaying the page.
Originally posted by ben oliver:

can I do

...="javascript:myscript(MyForm.addr.city)" ?

No, you can't. Because the period has meaning in JavaScript, you can't use this construct when referring to a name that had a period in it. You must find other ways to refer to the object. Example:

[ June 10, 2008: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 374
Hi Merrill, I guess you misunderstood me.

My Action form "MyForm" has a variable called "addr" which is of a composite data type "Address", it has "city" as its variable. Now in my JSP, I have a field called "city" where I will display or input "city" name for the "addr" variable. I want to do some javascript validation on this field value, so I have

<input type="text" name=".." value=..
onxxxx="javascript:validateCity(MyForm.addr.city)"/>

I did NOT mean to use a value with dot value inside, I want to pass the "city" value of "addr" of "MyForm" to this javascript method for validation. Does this work ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to specify composite data in s struts FORM
 
Similar Threads
COMPOSITE PATTERN
def of Value Object Pattern
constructors with arguments calling constructors with arguments
HFSJ Question in JSTL
Rich Faces 4.0 Autocomplete