> The problem is, when i submit the form, i cannot get the value of the
> option (an Object of type Ob1 gotten from property="id") passed to the
> next Action... if i try with primitives, there's no problem...
> everything works as it should... but with an object... it just does not
> work.
There are no objects in HTML forms... it's just text. The only thing the
browser is going to send back to the server is the name and value of each
element. (Except for file uploads, I suppose.)
> I have a ValidatorForm, say VF and one of it's attibutes called
> organismo is an object of type Ob1, Ob1 being a bean definded in
[quoted text clipped - 9 lines]
> labelProperty="desFederacion"/>
> </html:select>
Try this:
<html:select property="organismo.a">
Struts (actually BeanUtils) will call form.getOrganismo().setA( ... ) with
whatever value was selected.
Then you have a small problem, because an HTML select list will only send
the 'value' attribute, which is usually an id of some kind. The text
description that's displayed in the list is not sent to the server.
But this isn't much of a problem-- after all, you created that list, so you
know what's in it. Once you know what value was chosen, you can look up the
description. (A Map might work better than a List here, it's easier to
retrieve the value you need.)
I only store the 'code' (your 'id') in my forms, then I have a bunch of Maps
sitting in Application scope that hold the values. I use the Maps both to
populate the select lists, and also to display the description of the
selected item in the 'confirmation' page.
HTH,

Signature
Wendy Smoak
José Antonio - 19 Jun 2005 03:25 GMT
Thanks a lot Wendy... so it's not possible to set an Object as an ID in
a html form... mmm, i expected so...i was just hoping that not to be
that way.
The problem is, when a user chooses an option, i want that option to be
associated with a couple of values as ID, not just one string but two.
I could get the pair of values and concatenate the with some character,
handle them in the form as a unique string composed of the two values
and them split them in the Action that follows the jsp to have them as
two again... but i don't feel that to be right... but as it seems... i
have no choice.
Do i have a choice? Any suggestion?
Thanks once again.
Wendy Smoak - 19 Jun 2005 06:09 GMT
> I could get the pair of values and concatenate the with some character,
> handle them in the form as a unique string composed of the two values
> and them split them in the Action that follows the jsp to have them as
> two again... but i don't feel that to be right... but as it seems... i
> have no choice.
You don't need the 'description' String to come in from the browser-- you're
the one who put it in the List that created the drop-down select list to
begin with. When the browser tells you what ID was selected, find the
description again from wherever you got it in the first place.
My Form beans don't have anything but Strings and a few booleans for
checkboxes. From those I populate objects with more complex types. IMO, It
sounds like you might be putting too much in the Form bean. It should be
fairly simple, its only job is to keep track of user input.

Signature
Wendy Smoak
José Antonio - 20 Jun 2005 16:38 GMT
Yes, usually i do that and try to keep forms as simple as posible, but
this time i find it hard to do so with a couple of drop-down lists
because i populate them from a database where their key value is
composed of an ID an a date. So when i'm done with choosing which one
do i want, to really mean the option i chose, in the next step of the
flow i really need to get both the id and the date. With those values
i can take on an get the others, as the description or whatever, thats
true.
I generate the lists in the first place from a select with no
variables, i just get all the rows in a table. The natural way would be
to set the pair of values (the key) in an Object, but i cannot that.
Again, i must pass the key composed of two values and from then i would
restore the row from the database if needed.
Any way to do that?
Thanks in advance.
Wendy Smoak - 20 Jun 2005 17:42 GMT
> Again, i must pass the key composed of two values
>
> Any way to do that?
Various ways... your goal must be to get both of the Strings concatenated in
what becomes the 'value' of the HTML <option> tag.
You could provide an additional 'get' method in your bean that returns the
concatenated String, or else stop using <html:options> and instead do the
iteration yourself, using <html:option>.
You might want to look at JSTL and the Struts-EL tags, using expressions in
the Struts <html:option> tag should make this job fairly easy.
Then you'll have to split the String into your two values, either with
clever 'get' methods in your form, or else in the Action when you need the
values.

Signature
Wendy Smoak
José Antonio - 20 Jun 2005 21:37 GMT
I did it concatenating the values prior to sending them to the form,
and got them split with clever 'get' methods in the Action... it works
pretty well.
I'll also loot at JSTL to see what else can i do.
Thank you very much Wendy.