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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:47:24+00:00 2026-05-22T11:47:24+00:00

I’m having trouble using a selectOneRadio component. I get a NullPointerException in my Converter’s

  • 0

I’m having trouble using a selectOneRadio component. I get a NullPointerException in my Converter’s getAsString. That exception is thrown before I even get to see that component.

This is how it looks like:

            <h:selectOneRadio id="bookA"
                value="#{bookHandler.compareBookA}">
                 <f:converter converterId="bookConverter" />
                <f:selectItems value="#{bookHandler.selectedBooks}"
                    var="book" itemLabel="#{book.shortname}" itemValue="#{book}" />
            </h:selectOneRadio>

The property compareBookA is an object of type Book.

This is the method that throws the NPE:

@Override
public String getAsString(FacesContext fc, UIComponent uic, Object value)
        throws ConverterException {
    Book book = (Book) value;
    if (book == null ) {
        throw new ConverterException("NPE...");
    }
    return book.getShortname();
}

I have also overwritten toString().

For some reason the component is rendered if I change it to selectManyCheckbox (and leave the rest like it is).

I’m using JSF 2 (MyFaces implementation) with Tomahawk on Tomcat.

Bonus question: Why do I need a converter in the first place? If I leave the converter away, the component is rendered, but I want to pass the chosen book to some action method and it won’t be a Book then.

Any ideas?
Thanks!

  • 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-22T11:47:25+00:00Added an answer on May 22, 2026 at 11:47 am

    Apparently #{bookHandler.compareBookA} is just null.

    You shouldn’t throw ConverterException when Book is null, but just let it go.

    return (book != null) ? book.getShortname() : null;
    

    As to the bonus question, you need converters because the HTML response is basically one large string. All Java objects needs to be converted to string to get embedded in the HTML response. Also, the HTTP request parameters are by default strings. The request.getParameter() returns String. HTML/HTTP has totally no notion of how to handle and pass fullworthy Java objects.

    See also:

    • Conversion Error setting value for 'null Converter'
    • Objects in h:selectOneMenu
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.