-2

I have a strange problem right now (see title of question). It says it cant cast to said object even though there should be no casting required.

JSF-Page: http://pastebin.com/0aFNWc4h Bean: http://pastebin.com/vtA552fA

Every selected item of the SelectManyCheckbox should be stored as TeamTO-object in this list.

Field declaration in the Bean:

private List<TeamTO> preSelectionRecipientsTeams;

Snippet from the jsf page:

<h:selectManyCheckbox id="preSelectionRecipientsTeams" value="#{sendMailBean.preSelectionRecipientsTeams}">

Upon trying to iterate over this list

for (TeamTO t : getPreSelectionRecipientsTeams()) {...}

I get said error. Any ideas?

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
dNhax
  • 27
  • 7
  • Did you try to debug to see which object are in the list in fact? there is a case it fills with Strings in some other place in the code. – Stan Dec 21 '15 at 11:04
  • 1
    post code **here**... not somewhere else... and make it an [mcve] – Kukeltje Dec 21 '15 at 11:06
  • "System.out.println(getPreSelectionRecipientsTeams());" prints "Information: [TeamTO#2, TeamTO#10]" (correct behavior after selecting some objects via the SelectManyCheckbox) – dNhax Dec 21 '15 at 11:06
  • @Kukeltje Why have you removed the jsf tag? It seems to be applicable to me. – Jens Schauder Dec 21 '15 at 11:39
  • Sorry, I did not check the code (I never look at external files) and there is a jsf page... so it could indeed be jsf related. Sorry, I'll re-add it – Kukeltje Dec 21 '15 at 11:41

1 Answers1

0
getPreSelectionRecipientsTeams()

contains Strings, although it shouldn't, judging from it's type.

Find the place where it get's it content from and fix that.

From your updated question I infer the following:

Your bean contains a collection of the desired type, but you have not registered a converter to make JSF actually convert the Strings, it receives via http into those objects.

So: write a Converter and register it to your JSF component.

Probably a good point to start reading about all this is: http://download.oracle.com/otn_hosted_doc/jdeveloper/j2ee101302/jsf_apps/eventvalidate/sf_avc_process.html

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
  • preSelectionRecipientsTeams is a List of Strings. `private List preSelectionRecipientsTeams;` The selected items of the SelectManyCheckbox should be stored as TeamTO in said list. `` Am I overseeing some jsf-specific conversion of types? – dNhax Dec 21 '15 at 11:15
  • Sorry, but I'm not even trying to decipher code in comments. If you think it is relevant to the question, put it in the question. – Jens Schauder Dec 21 '15 at 11:17