简体   繁体   中英

get updated cell in datatable - primefaces - java

In my datatable has several fields. My intention is that when you edit any of these fields and press the button , this row will be sent to my backbean to be changed.

The problem is that when the object is sent to the Backbean , it comes with the original properties (values).

I need the datatable to be updated when the field is edited and send this new value to my backbean.

Any sugestions? in add, im trying to avoid using primefaces in my backbean... ive made it so far..

My datatable

<h:form id="formBean">
<p:dataTable id="dataTableBean"
             var="modulo" 
             value="#{moduloBean.listModulo}"
             paginator="true"
             rows="15"
             resizableColumns="true">


    <p:column headerText="Id"><h:outputText value="#{modulo.id}"/></p:column>
    <p:column id="columnNmDescricao"
              headerText="Descrição">
        <p:inputText id="inputNmDescricao" value="#{modulo.nmDescricao}">
            <p:ajax event="change"
                    update=":formTabFuncionalidade:tabViewTabFuncionalidade:tabViewAcaoFuncionalidade:formBean:dataTableBean"
                    process="@this :formTabFuncionalidade:tabViewTabFuncionalidade:tabViewAcaoFuncionalidade:formBean:dataTableBean:0:inputNmDescricao"/>
        </p:inputText>
    </p:column>
    <p:column headerText="Ativo"><h:outputText value="#{modulo.ativo.nmAtivo}"/></p:column>

    <!-- Coluna para Ações. Trocar apenas os 2 últimos parâmetros do callSubAcaoMethod -->
    <p:column id="columnAcoes"
              headerText="Ações">
        <c:forEach items="#{funcionalidade.listAcao}"
                   var="subAcao">
            <c:if test="#{!subAcao.tipoAcao.flPrincipal}">
                <p:commandButton id="btnAcoes"
                                 value="#{subAcao.tipoAcao.nmDescricao}"
                                 icon="#{subAcao.tipoAcao.nmIcone}"
                                 action="#{segurancaBean.callSubAcaoMethod(subAcao, moduloBean.class, modulo)}"
                                 process="@this"/>
            </c:if>
        </c:forEach>
    </p:column>
</p:dataTable>  
</h:form>

my callSubAcaoMethod

    public void callSubAcaoMethod(Acao acao, Class bean, Object objeto){
    try {
        /* Método de instanciar um objeto dinamicamente em uso de CDI */
        Object objBean = CDI.current().select(bean).get();

        /* Estou chamando o método do Bean, dando como parâmetro suas ações e a classe que será alterada */
        Method method = bean.getMethod(acao.getTipoAcao().getNmBean(), objeto.getClass());
        method.invoke(objBean, objeto);

    } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
        Logger.getLogger(SegurancaBean.class.getName()).log(Level.SEVERE, null, ex);
    }
}

The method i want to call

    public void btnAlterar(Modulo entity){
    System.out.println(entity);
    System.out.println(entity.getId());
    System.out.println(entity.getNmDescricao());
    System.out.println(entity.getAtivo().getNmAtivo()); 
}

Replace

<p:inputText id="modelInput" value="#{modulo.nmDescricao}" style="width:96%"/>

with

<p:inputText id="modelInput" value="#{modulo.nmDescricao}" style="width:96%">
<p:ajax event="change" proces="@this :formID:dataTable:modelInput" update=":formID:dataTable"></p:ajax></p:inputText>

You need to update model's new value with ajax and update table with it, so when you send row object to back been it is with new vale.

With button you send row object to back-bean method btnAlterar like this.

<p:commandButton value="#{subAcao.tipoAcao.nmDescricao}"
   icon="#{subAcao.tipoAcao.nmIcone}"
   action="#{WhatEverBeanHasMe.btnAlterar(modulo)}"
   process="@this"
 />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM