What you are seeing in the combo is the result of invoking the toString()
method of your Client class. When JSF receives a request, it transforms the html into a component tree. When it generates the rensponse, it renders each of the components to html. Whenever this happens, within the life cycle of an order, what JSF does is convert the data, from how they are represented from html to objects and vice versa. In your case, the framework must convert each element of the html (text) combo to your client object (and from client object to text when rendering the combo). To define how this conversion should be done we can implement the interface javax.faces.Converter . It has two methods to implement:
public Object getAsObject(FacesContext context, UIComponent component,
String value);
In this method you should define how to transform the object (to the client) after choosing one of the options of the combo.
public String getAsString(FacesContext context, UIComponent component,
Object value);
In this other method you should define what you are going to show as an option of the combo.
Notice that the getAsObject
method will be invoked in the post and the getAsString
method will be invoked when generating the response.
Another option you have is to use Omnifaces . It has many utilities that save your life many times. For your particular case, Omnifaces provides you with a SelectItemsConverter . Take a look at the documentation, but you'll see that with this special Omniface converter you only need to have a "good toString ()" with which you can uniquely identify each entity (in your case, each client). From what I see, your implementation of toString
does what this converter requires and it should not be difficult to use it in your project.
All this if you want that when selecting an option a client object is saved in your ManagedBean. Now, if you only want to save the id of the selected client, perhaps with something like this you reach:
<h:selectOneMenu id="clienteid" value="{#historialController.selected.clienteid}"
title="#{bundle.CreateHistorialTitle_clienteid}" required="true"
requiredMessage="#{bundle.CreateHistorialRequiredMessage_clienteid}">
<f:selectItems value="#{clientesController.itemsAvailableSelectOne}"
var="cliente" itemLabel="#{cliente.nombre}" itemValue="#{cliente.id}}/>
</h:selectOneMenu>
In the f:selectItems
tag you can declare a variable with the var attribute which you can then use to define the tag: itemLabel
and the value that will be saved in your ManagedBean: itemValue
.