I have a List <Hotel> object and I need to save it to a SelectItem[] object. How do I code this?
public List <Hotel> hotel;
public SelectItem[] food;
// followed by getters and setters
I need to save the hotel object to a food object. How do I code this in Java?
Just construct
SelectItemobjects with the desired value and label using its constructor. For example, with the hotelidas value and hotelnameas label.By the way, a
List<SelectItem>is also supported by<f:selectItems>. That’s easier to create.Unrelated to the concrete problem, based on your question history, you’re using JSF 2.0. You can just use
List<Hotel>straight in the<f:selectItems>without the need for uglySelectItemwrapper model. See also your previous question: How to populate options of h:selectOneMenu from database?