Problems with selectOneMenu

Asked

Viewed 725 times

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 fields (columns) of the current row I want to edit are filled in.

A list is loaded on selectOnMenu but it doesn’t bring me the current line item 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>     

https://www.filepicker.io/api/file/Oiu8OXTT1eI0tTgEzTDK

Primefaces 4.0

Javax.faces 2.2.5

1 answer

2

Without analyzing the application details, I can’t tell you why the item is not selected.

However, I suggest that instead of selecting by the ID of an object (which may be null), create a Converter for the component selectOneMenu, in accordance with example of documentation. There’s one more 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 with no description or id at the top of the list and treat this in your Converter.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.