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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:10:41+00:00 2026-06-05T15:10:41+00:00

I am using PrimeFaces <p:dataTable> with pagination. I use <h:selectBooleancheckbox> with a Map property

  • 0

I am using PrimeFaces <p:dataTable> with pagination. I use <h:selectBooleancheckbox> with a Map property for corresponding row selection. The problem which I am facing is when I select and submit the values, there is a NullPointerException. The values are checked for particular rows only. I am using JSF 2.0 and PrimeFaces 3.0.

My page is:

<p:dataTable id="ngoPhotoTab" paginator="true" rows="10" value="#  {photoApprovelBean.lstNgoPhotos}" var="ngoPhoto">
    <p:column headerText="NgoName">
        #{ngoPhoto.ngoName}
    </p:column>
    <p:column headerText="Select">
        <h:selectBooleanCheckbox id="ngoSelect" layout="pageDirection" value="#{photoApprovelBean.checked[ngoPhoto.photo_id]}" />
    </p:column>
    <f:facet name="footer"> 
        <p:commandButton onclick="deletePhoto();" value="Delete" />
    </f:facet>
</p:dataTable>

Backing bean logic:

public class PhotoApprovelBean {

    public String deleteActPhoto() {
        List checkedItems = new ArrayList();

        try {
            for (Iterator<PhotoApprovelBean> itr = disAppPhotoList.iterator(); itr.hasNext();) {
                PhotoApprovelBean item = (PhotoApprovelBean) itr.next();

                if (checked.get(item.getPhotoId())) {
                    checkedItems.add(item.getPhotoId());
                }
            }

            toDeletePhoto(checkedItems);
        }catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }

    public Map<Long, Boolean> checked = new HashMap<Long, Boolean>();

    public Map<Long, Boolean> getChecked() {
        return checked;
    }
}

The NullPointerException is caused in the line if (checked.get(item.getPhotoId())). The The Map is filled with values of first page only. How is this caused and how can I solve it?

  • 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-05T15:10:42+00:00Added an answer on June 5, 2026 at 3:10 pm

    You got a NullPointerException, because the if statement expects a boolean, but the Map contains Boolean values only which can possibly be null. They will be null for other pages. The Boolean value of null can’t be autoboxed to a boolean. You’d need to add a nullcheck.

    Boolean itemChecked = checked.get(item.getPhotoId());
    
    if (itemChecked != null && itemChecked) {
        // ...
    }
    

    Better, however, is to use PrimeFaces own <p:column selectionMode="multiple"> instead. It will remember the selection on other pages. The Map approach is only suitable if you don’t use pagination. See also the showcase example. Here’s how it can look like for you:

    <p:dataTable id="ngoPhotoTab" paginator="true" rows="10" 
        value="#{photoApprovelBean.lstNgoPhotos}" var="ngoPhoto"
        selection="#{photoApprovelBean.selectedNgoPhotos}" rowKey="#{ngoPhoto.photoId}"
    >
        <p:column headerText="NgoName">
            #{ngoPhoto.ngoName}
        </p:column>
        <p:column headerText="Select" selectionMode="multiple" />
        <f:facet name="footer"> 
            <p:commandButton onclick="deletePhoto();" value="Delete" />
        </f:facet>
    </p:dataTable>
    

    with

    private PhotoApprovelBean[] selectedNgoPhotos;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with a dataTable using PrimeFaces 3.2. The DataTable content is
I am trying to implement a Select All checkbox using primefaces component p:selectBooleanCheckbox and
Primefaces Datatable let you configure the filtering type you use for a column, using
We are using Primefaces 3M4 and one of our pages has a p:dataTable which
I am using PrimeFaces <p:fileUpload > with <h:inputText> inside. The problem which i am
I am using primefaces datatable with clickable rows and I need to find way
I'm using Primefaces 3.3.1 and have question. I have p:commandButton inside p:column of p:dataTable.
Hello i am using primefaces version 3.2 The ui layout which i am using
I'm using primefaces' accordion panel. Inside the tabs i have forms which are created
As can be seen here: primefaces scrolling DataTable And in the image: When using

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.