1

When I set the variable in my bean, the conversion is OK. Look the variables in the Image:

Without Conversion Error

When I use xhtml to set a variable, UI:repeat + p:selectCheckboxMenu I received this error:

 /* Caused by: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.util.List */

Look the variables:

With conversion Error

In my JSF I have:

<ui:repeat var="q" value="#{bean.questions}">
 <p:selectCheckboxMenu converter="javax.faces.Integer" filter="true" 
    value="#{bean.selectedDinamicRoadmap[q.id]}">
    <f:selectItems value="#{bean.roadmaps}" var="roadm" itemLabel="#{roadm.description} " itemValue="#{roadm.id}" />
    </p:selectCheckboxMenu>
</ui:repeat>

And in my bean I need save a selectedDinamicRoadmap[] And look my code for this:

private Map<Integer, List<Integer>> selectedDinamicRoadmap = new HashMap<Integer, List<Integer>>();
//gets and sets
public void save() {
 for (Entry<Integer, List<Integer>> ee : selectedDinamicRoadmap.entrySet()) {
  Integer key = ee.getKey();
  List<Integer> values = ee.getValue();  /* Caused by: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.util.List */
  for (Integer id : values) {
   //saveData
  }
 }
}

how could I fix this? Or what`s the best solution for this?

I have tried:

List<Integer> values = ee.getValue(); 
List<String> values = ee.getValue(); 
Integer[] values = ee.getValue();
String[] values = ee.getValue();  
Object[] values = ee.getValue();// <- It is working : WHY?

of course changing the necessary code.

Atiq
  • 14,435
  • 6
  • 54
  • 69
  • The error means that the map actually contains string arrays instead of string lists as values. – Jesper Nov 01 '16 at 20:36
  • When I try this: String[] values = ee.getValue(); Type mismatch: cannot convert from List to String[] – Rodrigo Ramos Nov 01 '16 at 20:42
  • 1
    Ofcourse, because you have a `Map>`. But somehow you did something type unsafe (or something else than your own code did) and you have a wrong type of object as the value in the map. – Jesper Nov 01 '16 at 20:47
  • I turn the solution as @BalusC suggested, but it isn`t worked – Rodrigo Ramos Nov 03 '16 at 13:46
  • 'isn't worked' is to vague, please be more specific – Kukeltje Nov 03 '16 at 14:54
  • @Kukeltje, I am sorry, I received this error: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.util.Collection in this line: items.addAll(entry.getValue()); I changed the code as a sample with the error – Rodrigo Ramos Nov 03 '16 at 16:10
  • @Kukeltje, you have some idea? When I use **String[] values = ee.getValue()** I received : **Type mismatch: cannot convert from List to String[]** You know where I learn about that conversions? – Rodrigo Ramos Nov 03 '16 at 17:46

0 Answers0