• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to specify composite data in s struts FORM

 
ben oliver
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
ben oliver
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic