Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8948611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:02:21+00:00 2026-06-15T13:02:21+00:00

I’m having some trouble when trying to select single rows in a datatable (I

  • 0

I’m having some trouble when trying to select single rows in a datatable (I can’t figure out what’s going on, because my code is based on the primefaces showcase).

The table is filled first with result matches, then I’m trying to select a row, and finally trying to do some process. The problem appears when I try to process that single row, none of the actual methods its being called.

   <h:form id="form2">
        <p:dialog header="Agregar Producto" widgetVar="dlgAgregarProducto" modal="true" width="800" height="300">  
            <h:outputText value="Código"/>   
            <h:inputText value="#{promocionController.strIdProducto}"/>
            <h:outputText value="Nombre"/>     
            <h:inputText value="#{promocionController.strNombre}"/>   
            <p:commandButton id="btnBuscarProducto" value="Buscar" action="#{promocionController.buscarProductosIdNombre}" update="tableBusqueda"/>  
            <p:commandButton id="btnAgregarProducto" value="Agregar" action="#{promocionController.agregarProductos}" />  

            <p:dataTable id="tableBusqueda" var="prod" value="#{promocionController.obtenerProductos()}" 
                         rowKey="#{prod.idProducto}" selection="#{promocionController.arrProductosSeleccionados}" selectionMode="single">

                <p:column style="width:24%">
                    <f:facet name="header">
                        <h:outputText value="Código"/>
                    </f:facet>
                    <h:outputText value="#{prod.idProducto}"/>
                </p:column>

                <p:column style="width:24%">
                    <f:facet name="header">
                        <h:outputText value="Foto"/>
                    </f:facet>
                    <h:outputText value="foto"/>
                </p:column>                

                <p:column style="width:24%">
                    <f:facet name="header">
                        <h:outputText value="Descripción"/>
                    </f:facet>
                    <h:outputText value="#{prod.descripcion}"/>
                </p:column>

                <p:column style="width:24%">
                    <f:facet name="header">
                        <h:outputText value="Marca"/>
                    </f:facet>
                    <h:outputText value=""/>
                </p:column>

                <p:column style="width:24%">
                    <f:facet name="header">
                        <h:outputText value="Modelo"/>
                    </f:facet>
                    <h:outputText value="#{prod.modelo}"/>
                </p:column>

                <p:column style="width:24%">
                    <f:facet name="header">
                        <h:outputText value="Precio"/>
                    </f:facet>
                    <h:outputText value="#{prod.precio}"/>
                </p:column> 

            </p:dataTable>                            
        </p:dialog> 
    </h:form>

Backing bean:

@ManagedBean(name = "promocionController")
@SessionScoped
public class PromocionCO {
    arrProductosPromocion = new ArrayList<Producto>();
    arrProductosSeleccionados = new ArrayList<Producto>();
}
public void buscarProductosIdNombre() {
    productoDAO = new ProductoDAO();
    arrProductosBusqueda = new ArrayList<Producto>();
    arrProductosSeleccionados = new ArrayList<Producto>();
    // si la búsqueda es por nombre
    if (strIdProducto.compareTo("") == 0) {
        arrProductosBusqueda = productoDAO.obtenerProductosPorNombre(strNombre);
    } // si la búsqueda es por id
    else {
        producto = productoDAO.obtenerProductoPorId(strIdProducto);
        if (producto != null) {
            arrProductosBusqueda.add(producto);
        } else {
            arrProductosBusqueda = null;
        }
    }
}

public void agregarProductos() {
    for (int i = 0; i < arrProductosSeleccionados.size(); i++) {
        arrProductosPromocion.add(arrProductosSeleccionados.get(i));
    }
}
public ArrayList<Producto> obtenerProductos() {
    return arrProductosBusqueda;
}
public ArrayList<Producto> getArrProductosSeleccionados() {
    return arrProductosSeleccionados;
}

public void setArrProductosSeleccionados(ArrayList<Producto> arrProductosSeleccionados) {
    if (arrProductosSeleccionados != null) {
        this.arrProductosSeleccionados = arrProductosSeleccionados;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:02:22+00:00Added an answer on June 15, 2026 at 1:02 pm

    This is because your selection attribute points to an ArrayList of Producto instead of a single element. Since you are using datatable with selectionMode="single" the selected attribute should point a single element in your backing bean:

    Producto selectedProducto;
    
    public Producto getSelectedProducto() {
        return selectedProducto;
    }
    
    public void setSelectedProducto(Producto producto) {
        selectedProducto = producto;
    }
    

    Finally, specify this element in your dataTable selection:

     <p:dataTable id="tableBusqueda" var="prod" selectionMode="single"
                   value="#{promocionController.obtenerProductos}" 
                   selection="#{promocionController.selectedProducto}">
    

    Now after selecting a row the public void setSelectedProducto(Producto producto) method will be called.


    Unrelated to the concrete problem, it is more preferable to use getter/setter methods when pointing to a value in your backing bean:

    <p:dataTable id="tableBusqueda" var="prod" 
                 value="#{promocionController.obtenerProductos}" .../>
    

    In general, an appropriate getter/setter should looks like get<NameOfTheObject>, in your case:

    public List<Producto> getObtenerProductos()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm trying to create an if statement in PHP that prevents a single post
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.