I'm using JSF 2.1 and Tomcat 7. I have the following PrimeFaces select one menu:
<p:selectOneMenu id="idMarcaEdit"
value="#{cfgCentraleController.selMarcaEdit}"
var="p"
height="250"
effect="fade"
converter="marcaConverter"
>
<f:selectItems value="#{cfgCentraleController.marche}" var="c" itemLabel="#{c.marca}-#{c.modello}-#{c.versione}" itemValue="#{c}"/>
<p:column>
<h:outputText value="#{p.marca}" />
</p:column>
<p:column>
<h:outputText value="#{p.modello}" />
</p:column>
<p:column>
<h:outputText value="#{p.versione}" />
</p:column>
<p:column>
<h:outputText value="#{p.provisioning}" />
</p:column>
</p:selectOneMenu>
I have this in #{cfgCentraleController}
private List<Marca> marche;
private Marca selMarcaEdit;
public Marca getSelMarcaEdit() {
return selMarcaEdit;
}
public void setSelMarcaEdit( Marca selMarcaEdit ) {
this.selMarcaEdit = selMarcaEdit;
this.selectedCentrale.setIdRete( this.selMarcaEdit.getIdMarca());
}
public List<Marca> getMarche() {
return marche;
}
It works fine, but I don't realy need the whole entity to be submitted. I just need its ID.
I'm using OmniFaces for the converter:
import org.omnifaces.converter.SelectItemsConverter;
@Override
public String getAsString( FacesContext context, UIComponent component, Object value ) {
Integer id = (value instanceof Marca) ? ((Marca) value).getIdMarca() : null;
return (id != null) ? String.valueOf( id ) : null;
}
How do I obtain only the ID of the entity in the model?