Object pasing from selectOneMenu

Hi there,

I have got an input.jsp witch creates appointments. Each Appointment Object has an owner witch is an Object of class Person. Here an abstract of the jsp:

<h:selectOneMenu value="#{AppointmentController.currentAppointment .owner}">

<f:selectItems value="#{PersonController.possiblePersons}" />

</h:selectOneMenu>

Some how there are always only Strings inside the selectOneMenu. That's why I cannot pass the input into the owner variable of Appointment.

How do I solve this problem? How do I fill the selectOneMenu with Objects? And how do I get them out?

Felix

[690 byte] By [FT77a] at [2007-11-27 8:26:40]
# 1

This should be straight forward but I cannot tell from below example.

PersonController.possiblePersons should return a list of SelectItems where the value is the person object and the label would be how you want the person to show up in the list box.

ApointmentController.currentAppointment.owner should be returning a Person object.

I am guessing that PersonController is returning a list of People and this will not work.

smurray_eriea at 2007-7-12 20:16:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Thanks for your answer,

the selectonemenu is fine. it receives the selectitems correctly from an arraylist from PersonController:

public void loadPersons(){

this.setUp();

setPossiblePersons(new ArrayList<Person>());

Person aPerson=new Person();

Query query =session.createQuery("from Person ");

Iterator<Person> iterator = query.list().iterator();

while(iterator.hasNext()) {

aPerson = iterator.next();

if(aPerson!=null && aPerson.getName()!=null){

getPossiblePersons().add(new SelectItem (aPerson, aPerson.getName()));

}

}

session.close();

}

It seems that I have a problem with passing the actual selection to my appointment.

<h:selectOneMenu value="#{AppointmentController.currentAppointment.owner}">

<f:selectItems value="#{PersonController.possiblePersons}" />

</h:selectOneMenu>

value="#{AppointmentController.currentAppointment.owner} does not work!

FT77a at 2007-7-12 20:16:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
probably u can override toString() in Person class so that it returns owner name only.public String toString(){ return this.owner;}
veerjaa at 2007-7-12 20:16:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

I do not think that this is the solution.

I believe my getter-Method in AppointmentController is wrong:

public class AppointmentController {

.....

private SelectItem owner=new SelectItem();

.....

public SelectItem getOwner() {

currentAppointment.setOwner((Person)owner.getValue());

return owner;

}

public void setOwner(SelectItem owner) {

this.owner= owner

}

FT77a at 2007-7-12 20:16:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...