3

I want to get the selection value from dataTable to set in my Managed Bean but in the managed bean just set null. How can I set the selection value ?

 <h:form id="formcancel">
    <p:dataTable id="tablaprecan" var="xd" value="#{cancelacionMB.resultados}" rowKey="#{xd.folio}"
                 selection="#{cancelacionMB.cliente}" selectionMode="single" >
        <f:facet name="header">
            Solicitudes de Precancelacion
        </f:facet>

        <p:column headerText="Folio">
            <h:outputText value="#{xd.folio}" />
        </p:column>

        <p:column headerText="Cliente">
            <h:outputText value="#{xd.id_cliente}" />
        </p:column>

        <p:column headerText="Nombre del Cliente">
            <h:outputText value="#{xd.nombre_cliente}" />
        </p:column>

        <p:column headerText="Fecha Precancelacion">
            <h:outputText value="#{xd.timestamp_precancelacion}" />
        </p:column>
        <f:facet name="footer">
            <p:commandButton id="viewButton" value="Cancelar Banca" icon="ui-icon-gear"
                             update="tablaprecan" actionListener="#{cancelacionMB.cancelarBE}" rendered="true" />
        </f:facet>
    </p:dataTable>
</h:form>

and this is my Managed Bean private CancelacionMB cliente;

public CancelacionMB getCliente() {
    return cliente;
}

public void setCliente(CancelacionMB cliente) {
    this.cliente = cliente;
}
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
ReN FractaL
  • 41
  • 1
  • 6

1 Answers1

1

This construct will fail if the bean is request scoped and the data is not preserved during (post)construct, but only during some action method. Request scoped beans are garbaged by end of response. When you select a row and submit the form, a brand new one would be created with all properties set to default (or whatever the (post)constructor made of it).

If you're preparing the data in some action method, e.g. after submitting a search form, then you should put the bean in the view scope in order to keep the data alive across subsequent postback requests.

@ManagedBean
@ViewScoped
public class CancelacionMB {
    // ...
}

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Hello BalusC,I was using it @ManagedBean(name = "cancelacionMB") @SessionScoped But now I changed it to @ViewScoped and is the same in my construct ` public CancelacionMB() { FacesContext context = FacesContext.getCurrentInstance(); HttpSession session = (HttpSession) context.getExternalContext().getSession(false); if (session != null) { LoginMB lmb = (LoginMB) session.getAttribute("user"); if (lmb != null) { this.user_cancelo = lmb.getUser(); } } }` – ReN FractaL Dec 20 '12 at 16:37
  • Hello again, I solved it with your idea but I have changed the faces-config.xml to it cancelacionMB mx.org.banbicen.controller.CancelacionMB session I dont know why my tags @ManagedBean(name = "cancelacionMB") @SessionScoped dont work. a lot of thanks – ReN FractaL Dec 20 '12 at 17:08