Problems with selectOneMenu

2

I have a table and in this table I have the option to edit.

Clicking on the edit option opens the dialog and all the fields (columns) of the current line I want to edit are populated.

A list is loaded into selectOnMenu but it does not bring me the item of the current line I chose to edit.

<p:dialog id="dl-editar" widgetVar="editar" header="Editar Medicamento"
    showEffect="fade" hideEffect="explode" closable="true" closeOnEscape="true"
    resizable="false" maximizable="false" modal="true" appendTo="@(body)">

        <p:spacer height="10px;"/>
        <h:form id="form-editar">
        <p:focus/>
            <h:panelGrid id="panel-editar" columns="1">
                <p:outputLabel value="Medicamento"/>
                <p:inputText   value="#{BeanMedicamento.medicamento.nome}" size="32" maxlength="80" />
                <p:outputLabel value="Concentracao"/>
                <p:inputText   value="#{BeanMedicamento.medicamento.concentracao}" size="10" maxlength="80"/>
                <p:outputLabel value="Preco" />
                <p:inputText   value="#{BeanMedicamento.medicamento.preco}" size="10"/>
                <p:outputLabel value="Quantidade"/>
                <p:inputText   value="#{BeanMedicamento.medicamento.quantidade}" size="10"/>
                <p:outputLabel value="Laboratorio"/>
                <p:selectOneMenu value="#{BeanMedicamento.medicamento.laboratorio.id}" filter="true">
                    <f:selectItem  itemLabel="Selecione" itemValue=""/>
                    <f:selectItems value="#{BeanMedicamento.listaLaboratorio}"  var="lista"
                        itemLabel="#{lista.sigla}" itemValue="#{lista.id}" />
                </p:selectOneMenu>
            </h:panelGrid>

            <h:panelGrid columns="3">
                <p:spacer width="35px;"/>
                <p:commandButton value="Sim" icon="ui-icon-check" 
                actionListener="#{BeanMedicamento.editar}"
                oncomplete="PF('editar').hide(); tbmedicamento.clearFilters()"
                update=":form-tabela:tabela :mensagem"/>
                <p:commandButton value="Não" icon="ui-icon-close"
                oncomplete="PF('editar').hide(); tbmedicamento.clearFilters()"
                update=":form-tabela:tabela"/>
            </h:panelGrid>
        <p:spacer height="10px;"/>  
        </h:form>
    </p:dialog>     

Primefaces 4.0

Javax.faces 2.2.5

    
asked by anonymous 06.10.2014 / 03:19

1 answer

2

Without reviewing the app's details, I can not tell you why the item is not selected.

However, I suggest that instead of selecting by the ID of an object (which can be null), create a Converter for the selectOneMenu component, as documentation example . Here's another example here .

This will allow you to directly select the lab, for example:

<p:selectOneMenu value="#{BeanMedicamento.medicamento.laboratorio}" 
        converter="laboratorioConverter" filter="true">
    <f:selectItems value="#{BeanMedicamento.listaLaboratorio}" var="lista"
                    itemLabel="#{lista.sigla}" itemValue="#{lista}" />
</p:selectOneMenu>

To have an empty item, add a Lab without description or id at the top of the list and treat this in your Converter .

    
06.10.2014 / 15:57