Note that there are some explanatory texts on larger screens.

plurals
  1. POSet only entity ID instead of whole entity in p:selectOneMenu
    primarykey
    data
    text
    <p>I'm using JSF 2.1 and Tomcat 7. I have the following PrimeFaces select one menu:</p> <pre><code>&lt;p:selectOneMenu id="idMarcaEdit" value="#{cfgCentraleController.selMarcaEdit}" var="p" height="250" effect="fade" converter="marcaConverter" &gt; &lt;f:selectItems value="#{cfgCentraleController.marche}" var="c" itemLabel="#{c.marca}-#{c.modello}-#{c.versione}" itemValue="#{c}"/&gt; &lt;p:column&gt; &lt;h:outputText value="#{p.marca}" /&gt; &lt;/p:column&gt; &lt;p:column&gt; &lt;h:outputText value="#{p.modello}" /&gt; &lt;/p:column&gt; &lt;p:column&gt; &lt;h:outputText value="#{p.versione}" /&gt; &lt;/p:column&gt; &lt;p:column&gt; &lt;h:outputText value="#{p.provisioning}" /&gt; &lt;/p:column&gt; &lt;/p:selectOneMenu&gt; </code></pre> <p>I have this in <code>#{cfgCentraleController}</code></p> <pre><code>private List&lt;Marca&gt; 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&lt;Marca&gt; getMarche() { return marche; } </code></pre> <p>It works fine, but I don't realy need the whole entity to be submitted. I just need its ID.</p> <p>I'm using OmniFaces for the converter:</p> <pre><code>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; } </code></pre> <p>How do I obtain only the ID of the entity in the model? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload