Problems with editable <p:datatable

Asked

Viewed 100 times

0

Good evening. I’m having trouble updating an editable datatable I created here. It reads the values, but does not assign them to the Managedbean object so I can persist.

Follows Code of the Bean

public void onCellEdit(CellEditEvent event) {
    Object oldValue = event.getOldValue();
    Object newValue = event.getNewValue();

    if (newValue != null && !newValue.equals(oldValue)) {
        FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed", "Old: " + oldValue + ", New:" + newValue);
        FacesContext.getCurrentInstance().addMessage(null, msg); 
    }
}

public void prepararIndicadores() {
    indicadoresUsuario = new ArrayList<>();
    IndicadorAmbiental iamb ;

    for(IndicadorAmbiental ia : getIndicadores()) {
        iamb = new IndicadorAmbiental();

        iamb.setDescricao(ia.getDescricao());
        indicadoresUsuario.add(iamb);
    }
}

public void cadastrarIndicadores() {
    for(IndicadorAmbiental ia : indicadoresUsuario) {
        ia.setAno(anoFinal);
        ia.setCenario(cenario);

        //indicadorAmbientalDAO.salvar(ia);
    }
}

View code

    <p:dataTable var="i" value="#{cenarioBean.indicadoresUsuario}"
        paginator="true" rows="15" class="dataTable" id="dataTable" editMode="cell"
        emptyMessage="Nenhum Indicador Cadastrado" widgetVar="indicadores"
        paginatorPosition="bottom" editable="true" >

        <p:ajax event="cellEdit" listener="#{cenarioBean.onCellEdit}" /> 

        <p:column headerText="Nome" styleClass="column">
            <h:outputText value="#{i.descricao}" />
        </p:column>

        <p:column headerText="Valor" styleClass="column" width="300">
            <p:cellEditor> 
                <f:facet name="output"><h:outputText value="#{i.valor}"/></f:facet> 
                <f:facet name="input"><p:spinner value="#{i.valor}" stepFactor="0.5" size="47" styleClass="componentePF text" /></f:facet>  
            </p:cellEditor>
        </p:column>
    </p:dataTable>

Editing the fields opens, but does not allow me to make changes. If someone can give a light, I thank!!!

1 answer

0

Check that the datatable code is inside one and that the attributes of the class used have getters and setters

  • It had all this! I created an auxiliary method to assist in the imputation of values.

Browser other questions tagged

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