Yes. Struts calls the setters in the target action based on the name of the form element. If the name attribute of your select field is 'status', it will try to call method setStatus, with the value of the form element--in this case id, as it's the listKey--as the parameter.
On Fri, Apr 18, 2008 at 8:36 PM, Griffith, Michael * < [EMAIL PROTECTED]> wrote: > Jukka, > > First of all, thanks for the reply. I don't think I made my question clear > enough. The form isn't editing the model/object called Status, its editing a > model on which Status is an associated object. Such as in this example, > where I have a class named Call, that has a field called Status, which is a > model object. > > Call Status > ----- ------- > id id > description description > dateCreated > status > > Given, this -- does your comment still hold? > > Thanks! > > MG > > Doesn't your example indicate that it would set the field called id > > -----Original Message----- > From: Jukka Välimaa [mailto:[EMAIL PROTECTED] > Sent: Friday, April 18, 2008 12:12 PM > To: Struts Users Mailing List > Subject: Re: Clarification on Type Conversion? > > name="status" means that you are trying to pass the status object itself > as > a parameter to a method setStatus. That is not possible--you need to pass > the id of the status if you want to indicate which status the user chose, > like this for example: > <s:select key="form.status" name="id" > list="statusList" > listKey="id" > listValue="description"/> > > You also need setId method in the action you submit the form to. > > On Fri, Apr 18, 2008 at 5:33 PM, Griffith, Michael * < > [EMAIL PROTECTED]> wrote: > > > Hello All, > > > > > > > > I am having a problem with Struts 2 form submission, because I believe a > > related <s:select> field is not being converted correctly. I have read > > the documentation at: http://struts.apache.org/2.x/docs/select.html and > > http://struts.apache.org/2.0.11.1/docs/type-conversion.html It is my > > understanding that I should not need to provide any custom converter, > > that this conversion should be automatic. When I submit the form, I > > receive the error: Invalid field value for field "status". > > > > > > > > Here is the setup: > > > > > > > > I have a form with a <s:select> field: > > > > <s:select key="form.status" name="status" > > > > list="statusList" > > > > listKey="id" > > > > listValue="description"/> > > > > > > > > The action has the method: > > > > > > > > public List<Status> getStatusList(){ > > > > return statusService.findAll(); > > > > } > > > > > > > > The model object that status is mapped to looks like this: > > > > > > > > @Entity > > > > @Table(name="STATUS") > > > > @Validation > > > > public class Status implements Identifiable, Serializable { > > > > > > > > private static final long serialVersionUID = > > -8017026685032314796L; > > > > private Integer id; > > > > private String description; > > > > > > > > @Id > > > > @GeneratedValue(strategy = GenerationType.AUTO) > > > > @Column(name = "ID", unique = true, nullable= false) > > > > public Integer getId() { > > > > return id; > > > > } > > > > > > > > public void setId(Integer id){ > > > > this.id= id; > > > > } > > > > > > > > @Column(name="DESCRIPTION", nullable= false) > > > > public String getDescription() { > > > > return description; > > > > } > > > > > > > > @RequiredStringValidator(message="Validation Error", > > key="validate.notEmpty", trim=true) > > > > public void setDescription(String description) { > > > > this.description = description; > > > > } > > > > > > > > I tried creating a mapping properties file called > > actionName-conversion.properties: > > > > KeyProperty_StatusList=id > > > > Element_StatusList=Status > > > > CreateIfNull_statusList=true > > > > > > > > No avail. I'm sure my problem is obvious, but I can't see it. Any help > > or suggestions would be much appreciated... > > > > > > > > Thanks in advance! > > > > Michael Griffith > > > > > > > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > >