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 8729673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:52:31+00:00 2026-06-13T08:52:31+00:00

I am using primefaces data table to display a list of data. I want

  • 0

I am using primefaces data table to display a list of data. I want my users to be able to select multiple rows after which an operation will be executed on the data represented by the selected rows. Everything works well up untill the operation is executed where i discover that the selection could not be resolved.

Below is my xhtml page

<h:form enctype="multipart/form-data" id="upload">
<primefaces-p:panel closable="false" collapsed="false" header="Excel Contact Uploader" id="pnlupload" rendered="true" toggleable="false" visible="true" widgetVar="pnlupload">

<primefaces-p:growl id="msg"  showDetail="true" life="3000" showSummary="true">

</primefaces-p:growl>
        <primefaces-p:fileUpload auto="true" 
        allowTypes="/(\.|\/)(xls)$/" 
        sizeLimit="1024000" 
        mode="advanced" 
        multiple="true" invalidFileMessage="Invalid file type" invalidSizeMessage="File too large" dragDropSupport="true" fileUploadListener="#{excelFileController.handleFileUpload}" showButtons="true" update="msg, tblcontacts
        " required="false"/>


      <br />
<br />


        <primefaces-p:scrollPanel rendered="true" style="height:200px;">
            <primefaces-p:dataTable  emptyMessage="No Contacts Uploaded" id="tblcontacts" rendered="true"  rows="8" 
            value="#{excelFileController.contacts}" var="contact" style="width:50pc;">
        <primefaces-p:column style="width:18px" headerText="Select"> 
       <h:selectBooleanCheckbox value="#{contact.selected}" />

        </primefaces-p:column>

        <primefaces-p:column headerText="File Name">  
        #{contact.groupName}  
        </primefaces-p:column>  
        <primefaces-p:column headerText="Number of Contacts">  
        #{contact.numberofentries}  
    </primefaces-p:column> 
    <primefaces-p:column>
    <h:button  outcome="blkedit?faces-redirect=true" rendered="true" value="Edit">
         <f:param name="contact" value="#{contact.contactId}"/>
        </h:button>
    </primefaces-p:column>
    </primefaces-p:dataTable>
   </primefaces-p:scrollPanel>

<br />
</primefaces-p:panel>
<h:commandButton value="Delete" id="btndelete" action="#{excelFileController.removeContact}"  immediate="true" disabled="false" rendered="true"/>
<h:message for="btndelete" />
</h:form>

and Below is my backing bean

@Named
@ViewAccessScoped
public class ExcelFileController implements Serializable, IFileController {

/**
 * 
 */
private static final long serialVersionUID = -8117258104485487921L;

@Inject
PhoneNumberFormatter formatter;

@Inject
@Authenticated
UserProfile profile;

public PhoneNumberFormatter getFormatter() {
    return formatter;
}

public void setFormatter(PhoneNumberFormatter formatter) {
    this.formatter = formatter;
}

@EJB
BulkContactDeleter deleter;

@Inject
Logger logger;

@Inject
@CurrentContext
FacesContext context;

@Inject
BulkSMSContactListProducer listProducer;

@Inject
ConfigurationListProducer producer;

private BulkSMSContacts[] contactsSelected;

private List<BulkSMSContacts> contacts;

public BulkSMSContacts[] getContactsSelected() {
    return contactsSelected;
}

public void setContactsSelected(BulkSMSContacts[] contactsSelected) {
    this.contactsSelected = contactsSelected;
}

/*
 * public BulkContactDataModel getContactDataModel() { return
 * contactDataModel; }
 */

@PostConstruct
public void init() {
    logger.log(Level.INFO, "Entering excel file controller");
    /*
     * contactDataModel = new BulkContactDataModel(
     * listProducer.getBulkSMSContacts());
     */
    this.contacts = listProducer.getBulkSMSContacts();

}

@Override
public String removeContact() {
    int contactsdeleted = 0;

    if (this.contacts != null) {
        /*
         * for (BulkSMSContacts contacts : contactsSelected) { if (contacts
         * != null) { deleter.deleteContact(contacts); contactsdeleted += 1;
         * }
         */
        for (BulkSMSContacts c : contacts) {
            if (c.isSelected()) {

                deleter.deleteContact(c);
                contactsdeleted += 1;
            }

        }
        contacts = listProducer.getBulkSMSContacts();

        logger.log(Level.INFO, "Deleted " + contactsdeleted + " Contacts");
        context.addMessage(null, new FacesMessage(
                FacesMessage.SEVERITY_INFO, "Success", contactsdeleted
                        + " entries where deleted successfully"));
    } else {
        context.addMessage(null, new FacesMessage(
                FacesMessage.SEVERITY_ERROR, "Error",
                "No contact file was selected!"));
    }
    return null;
}

public List<BulkSMSContacts> getContacts() {
    return contacts;
}

public void setContacts(List<BulkSMSContacts> contacts) {
    this.contacts = contacts;
}

}

Below is my model definition

@Entity
public class BulkSMSContacts implements Serializable {

private static final long serialVersionUID = -6444763251149211384L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@XmlAttribute
private long contactId;

@XmlElement
@NotNull(message = "message.validator.notnull")
@Size(min = 9, max = Integer.MAX_VALUE, message = "message.validator.size")
@Column(nullable = false, length = Integer.MAX_VALUE, unique = false)
@Basic(fetch = FetchType.EAGER)
private String contacts;

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "Id", nullable = false)
@XmlElement(type = SMSAccount.class)
private SMSAccount account;

@NotNull(message = "message.validator.notnull")
@Size(min = 2, max = 100, message = "message.validator.size")
@Column(length = 100, nullable = false, unique = false)
@XmlElement
private String groupName;

@Column(nullable = true)
private int numberofentries = 0;

@javax.persistence.Transient
private boolean selected;

//getters and setters

The problem is that when the delete button is clicked(albeit when the removeContact() method is called. All the rows evaluate to none being selected.

I have also tried using the primefaces showcase approach but still the sample problem.

Please am I doing something wrong??

  • 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-13T08:52:33+00:00Added an answer on June 13, 2026 at 8:52 am

    I don’t see why you set a selection attribute within an entity class.
    Try to do it this way

    1. set a data Model :

      public class BulkSMSContactsDataModel extends ListDataModel<BulkSMSContacts> implements SelectableDataModel<BulkSMSContacts> {    
      
      public BulkSMSContactsDataModel() {  
      }  
      
      public BulkSMSContactsDataModel(List<BulkSMSContacts> data) {  
          super(data);  
      }  
      
      @Override  
      public BulkSMSContacts getRowData(String rowKey) {         
         List<BulkSMSContacts> contacts = (List<BulkSMSContacts>) new yourDao.getListOfBulkSMSContacts(); //yourDAO :BulkSMSContactsSelector i guess
          for(BulkSMSContacts c : contacts) {  
              if(String.valueOf(c.getContactId()).equals(rowKey))  
                  return c;  
          }  
      
          return null;  
      }  
      
      @Override  
      public Object getRowKey(BulkSMSContacts obj) {  
          return String.valueOf(obj.getContactId());  
      }
      

      }

    2. configure your bean :

      public class ExcelFileController implements Serializable, IFileController {
          private BulkSMSContacts[] contactsSelected;
          private List<BulkSMSContacts> contacts;
          private BulkSMSContacts[] selectedcontacts;
          private BulkSMSContactsDataModel contactsList;
              public ExcelFileController() {
              contactsList = new BulkSMSContactsDataModel(contacts);
          }
          // getters and setters
          // the rest of your code 
      

      }

    3. configure your xhtml

      <p:dataTable  emptyMessage="No Contacts Uploaded" id="tblcontacts" rendered="true"  rows="8" value="#{excelFileController.contactsList}" var="contact" style="width:50pc;" selection="#{excelFileController.selectedcontacts}">
            <p:column selectionMode="multiple" style="width:20px" />
            <p:column headerText="File Name">  
              #{contact.groupName}  
            </p:column>  
            <p:column headerText="Number of Contacts">  
              #{contact.numberofentries}  
            </p:column>
             <!-- the rest -->
      

    4. Update your UI.

    5. use p instead of primefaces-p it will make it easier to read your Code. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using primefaces autocomplete componant for multiple columns. I am able to display
I'm using Primefaces 3.4 and trying to export a data-table with in-cell editing. It
I want to display some data through primefaces datalist component. To achieve this I
Is it possible to freeze first 3 columns of Primefaces' data table? I'm using
I want to dynamically load images from a database withing a PrimeFaces data table.
I am using primefaces and JSF 2.0. I have a data table with a
I am using JSF 2.0 and PrimeFaces 2.2. I have a data table whose
Hi I am using Primefaces 3.0.M and it's data table. I have set it
I am using the dataTable object of primefaces to display some data and I
I was using dataTable to display list of Objects (Primefaces 3.0) with no issues.

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.