さて、selectManyCheckbox の結果を整数配列に入れようとしているため、ターゲットがコレクションまたは配列ではないと言われている理由がわかりません。ユーザーが複数の数値を選択して配列に格納し、後で表示できる 1 ~ 50 のチェックボックスにすぎませんが、「ターゲット モデル タイプはコレクションまたは配列ではありません」というエラー メッセージが表示され続けます。これは、整数配列ではなくオブジェクト配列に保存する必要があるものですか? この同じ問題を扱っている他のスレッドがあることは知っていますが、私が見た他のスレッドは、一般的に誰かが間違ったタイプのチェックボックスを使用しているか、誰かが配列またはコレクションに保存していませんでした. どんな助けでも本当にありがたいです。
<p>
Pick Your Lotto Numbers
<h:selectManyCheckbox value="#{lottoBean.numbersPicked}"
layout="lineDirection">
<f:selectItems value="#{lottoBean.numberChoices}"/>
</h:selectManyCheckbox>
</p>
<p>
<h:commandButton value="Submit"
action="next.xhtml"/>
</p>
そして myLottoBean クラス...
int[]choices = new int[50];
int[]picked;
int[]actual;
int test = 5;
/**
* Creates a new instance of LottoBean
*/
@SuppressWarnings("empty-statement")
public LottoBean() {
picked = new int[6];
actual = new int[6];
}
public void setNumbersPicked(int[] chosen)
{
for(int i =0; i < 6; i++)
{
picked[i] = chosen[i];
}
}
@SuppressWarnings("empty-statement")
public String getNumbersPicked()
{
return Arrays.toString(picked);
}
public int[] getNumberChoices()
{
for (int i = 0; i < 50; i++)
{
choices[i] = i + 1;
}
return choices;
}
public String getNumbersDrawn()
{
Random num = new Random();
for (int i = 0; i < 6; i++)
{
int nextNum = num.nextInt(50);
int number = nextNum + 1;
actual[i] = number;
}
return Arrays.toString(actual);
}
}