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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:16:15+00:00 2026-05-26T14:16:15+00:00

I am trying to retrieve a set of values from database and assigned it

  • 0

I am trying to retrieve a set of values from database and assigned it to selectItem (Primefaces UI component). But it is not assigned rather it shows nullPointerException.

I have two view pages in my first page, am just having an command button to enter into a function for retrieving some data from DB, then i assigned those values to a selectITem(drop down) in another view page.

My first view page is

     <html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui">

<h:head></h:head>
    <h:body>
     <h:form>
      <p:panel header="autocomplete">
     <h:panelGrid columns="2">


       <p:commandButton value="Submit" action="#{receiveclass.retrieve}" ajax="false">     </p:commandButton>


 </h:panelGrid>

 </p:panel>
  </h:form>

 </h:body>              
    </html> 

java code for the action is..

         public String retrieve(){


    FacesContext context = FacesContext.getCurrentInstance();
        loginBean loginBean = (loginBean) context.getApplication().evaluateExpressionGet(context, "#{loginBean}", loginBean.class);
List<loginBean> retList=loginDao.retrieval();
        loginBean.setRetList(retList);

        return "success";

                }



}

In the above code the value is set properly to retList after retrieving it from Database,
Db part is written in loginDao.

loginBean is nothing but the managed bean of my next view page where i am having the selectItem tag, i called the setter of that selectItem with the retrieved list from DB.

the bean part is..

       List<loginBean> retList;



public List<loginBean> getRetList() {

    return retList;

}
public void setRetList(List<loginBean> retList) {
    this.retList = retList;

In my next view page, i have assigned the value to selectItems as

         <h:outputText value="Current City"></h:outputText>
<p:selectOneMenu style="width:150px" id="currentCity" value="#{loginBean.currentCity}" required="true" immediate="true" requiredMessage="Select your city" label="Country">
    <f:selectItem value="#{loginBean.retList}"></f:selectItem>
           </p:selectOneMenu>  

After execution my console says…

                 SEVERE: Error Rendering View[/login.xhtml]
     java.lang.NullPointerException
at                   org.apache.myfaces.shared_impl.renderkit.html.HtmlResponseWriterImpl.write(HtmlResponseWriterImpl.java:867)
at               org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeSelectItems(SelectOneMenuRenderer.java:282)
at                  org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeInput(SelectOneMenuRenderer.java:96)
at           org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeMarkup(SelectOneMenuRenderer.java:75)
at             org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeEnd(SelectOneMenuRenderer.java:53)

I have tried several ways, but no improvement.

  • 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-05-26T14:16:15+00:00Added an answer on May 26, 2026 at 2:16 pm

    There are 2 problems.

    First, the <f:selectItem> represents a single select item, but yet you’re passing a whole List of items through it. You should be using <f:selectItems> instead.

    <f:selectItems value="#{loginBean.retList}" />
    

    Second, PrimeFaces has a bug that it expects the select item label to be explicitly specified next to item value. So, you should specify both itemValue and itemLabel:

    <f:selectItems value="#{loginBean.retList}" var="item" itemValue="#{item}" itemLabel="#{item}" />
    

    See also:

    • java.lang.NullPointerException at java.io.PrintWriter.write
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iam trying to retrieve data from mysql database into stylesheet.php but it is not
I'm trying to retrieve values using VB.NET from a SQL database. How do I
I'm trying to retrieve options/values from my database in the from of an array
I'm trying to retrieve the SubItem in my ListView from another thread, but I
I'm trying to retrieve a file from a server using SFTP (as opposed to
I'm trying to retrieve an XML stream from a URL. For most URLs my
I'm trying to retrieve data from an SQL Server 2000 server, and place into
I am trying to retrieve the correct value from an ArrayList of objects (.NET
I'm trying to retrieve data from a POST method, code as follows: -(void)postXMLFeed:(NSString *)XMLStrPost
I am trying to update data while I am reading them from database, see

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.