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

The Archive Base Latest Questions

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

I have a property in my JSF managed bean: private List<Long> selectedDataSets; I initialize

  • 0

I have a property in my JSF managed bean:

private List<Long> selectedDataSets;

I initialize the list like this within an other method:

ArrayList<Long> longList = new ArrayList<>();

What happens is I get java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long right when it jumps on this foreach:

for (Long CRC : selectedDataSets) { ... }

Which is very odd. Debug shows that selectedDataSets are full of String values, but I thought that’s not even possible. Please describe me what exactly happened here.

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

    Apparently you bound the property to an UISelectMany component like <h:selectManyCheckbox> or <selectManyListbox> without explicitly specifying a Converter. In Java, the generic type is erased during runtime and JSF (more specifically, EL) does not know anything about the generic list type at all and defaults to String unless told otherwise by a Converter. It’s String because that’s just the default value type of HttpServletRequest#getParameterMap(). EL fills the list with submitted values by reflection and does not take any generic types into account.

    So, for example this should do it for you, with help of the builtin LongConverter:

    <h:selectManyCheckbox value="#{bean.selectedDataSets}" converter="javax.faces.Long">
    

    See also:

    • Use enum in h:selectManyCheckbox

    Note that this has nothing to do with Java 7’s diamond operator. You would have exactly the same problem when you have experimented with new ArrayList<Long>().

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

Sidebar

Related Questions

I am new to JSF and managed beans. I have a managed bean with
Problem Description: My injected Spring bean defined as a Managed-Property to a JSF backing
I have a session bean <managed-bean> <managed-bean-name>vdcAddBean</managed-bean-name> <managed-bean-class>com.cloud.appsportfolio.jsf.vdc.beans.VDCAddBean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> Now, I am injecting
In a managed bean I have a property of the type int. @ManagedBean @SessionScoped
I have a property called IsSecureConnection that is part of my object's interface. This
I have a property of type uint on my entity. Something like: public class
I have a property on my classes for logging service. private ILogger logger =
I have a property within a class, that I need to iterate through all
I have a Controller bean (SearchController) that has two managed bean as managed properties
I'm new to JSF, so this question might be strange. I have an inputText

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.