I am not sure I follow, what setter are you looking for?  Below is the
method that creates the array, and this is the code on the jsf page:

<tr><td><h:outputText value="#{assessment.currentQuestionText}" /></td></tr>
                      <tr><td><h:selectOneRadio id="q3answers"
value="#{assessment.q3}" layout="spread">
                                  <f:selectItems id="q3list"
value="#{assessment.*currentQuestionAnswers*}"/>
                              </h:selectOneRadio>
                              <br>
                          </td>
                      </tr>
<tr><td><h:outputText value="#{assessment.currentQuestionText}" /></td></tr>
                      <tr><td><h:selectOneRadio id="q4answers"
value="#{assessment.q4}" layout="spread">
                                  <f:selectItems id="q4list"
value="#{assessment.*currentQuestionAnswers*}"/>
                              </h:selectOneRadio>
                              <br>
                          </td>
                      </tr>

Thank you for the help, just really lost as to why this would not work if
there is more than one question on a page.


On Fri, Jun 26, 2009 at 11:01 AM, Sam <[email protected]> wrote:

> How about the setter?
>
>
> On Fri, Jun 26, 2009 at 9:52 AM, Scott Carter <[email protected]>wrote:
>
>> So here is the method that returns the selectItem list.  Each time it
>> creates a new array.  Do you still think this might be the issue?  I am
>> really lost on this one:
>>
>> public SelectItem[] getCurrentQuestionAnswers()
>>     {
>>         Question currentQuestion = this.questionList.get(questionCount);
>>
>>         int qWeight = currentQuestion.getQuestionWeight();
>>
>>         SelectItem[] answers = new SelectItem[5];
>>         answers[0] = new SelectItem(Integer.toString(qWeight) , "SA");
>>         answers[1] = new SelectItem(Integer.toString(qWeight - (qWeight /
>> 5)) , "A");
>>         answers[2] = new SelectItem(Integer.toString(qWeight - ((qWeight /
>> 5) * 2)), "N");
>>         answers[3] = new SelectItem(Integer.toString(qWeight - ((qWeight /
>> 5) * 3)) , "D");
>>         answers[4] = new SelectItem(Integer.toString(qWeight - ((qWeight /
>> 5) * 4)) , "SD");
>>
>>
>>
>>         this.questionCount++;
>>         return answers;
>>     }
>>
>> This method does declare a new array each time
>>
>>
>> On Fri, Jun 26, 2009 at 10:33 AM, Sam <[email protected]> wrote:
>>
>>> I think you may need to use different methods in the backing bean to
>>> return the selectitems.  Each question should have it's own instance of the
>>> selectItemList.  You can use a factory to return the different instances of
>>> the same list.
>>>
>>>
>>> On Thu, Jun 25, 2009 at 4:14 PM, Scott Carter 
>>> <[email protected]>wrote:
>>>
>>>> I have a jsf page which has a series of questions on it, each with radio
>>>> select for the answers.  Each of the questions uses the same set of answers
>>>> ( Agree . Disagree, Neutral ).  Since so many of the possible answer sets
>>>> repeat themselves I just put a method in the backing bean that returns an
>>>> array of SelectItem with the choices in it.
>>>>
>>>> This approach only works if the user only answers one question.  If more
>>>> than one question is answered (the user selects a radio button for more 
>>>> than
>>>> one question) then a validation error occurs.  Each of the
>>>> <h:selectOneRadio> tags has a unique id.  Also each of the <f:selectItem>
>>>> tags have a unique id, even though they call back to the same backing 
>>>> method
>>>> for the choices.  In the backing bean method a new array is created and
>>>> returned each time for the choices.  I even tested creating a new method
>>>> that returns an array of of SelectItem for the choices and had exactly the
>>>> same issue.
>>>>
>>>> If I change the code and put the <f:selectItem> tags directly inline in
>>>> the code instead of calling the backing bean for an array of selectItems ,
>>>> then everything works like it should.  I am very lost as to why I can not
>>>> use the <f:selectItems> functionality more than once in a page.  Here is a
>>>> piece of the code:
>>>>
>>>> <tr><td><h:outputText value="#{assessment.currentQuestionText}"
>>>> /></td></tr>
>>>>                       <tr><td><h:selectOneRadio id="q3answers"
>>>> value="#{assessment.q3}">
>>>>                                   <f:selectItems id="q3list"
>>>> value="#{assessment.currentQuestionAnswers}"/>
>>>>                               </h:selectOneRadio>
>>>>                               <br>
>>>>                           </td>
>>>>                       </tr>
>>>>
>>>>                       <tr><td><h:outputText
>>>> value="#{assessment.currentQuestionText}" /></td></tr>
>>>>                       <tr><td><h:selectOneRadio id="q4answers"
>>>> value="#{assessment.q4}">
>>>>                                   <f:selectItems id="q4list"
>>>> value="#{assessment.currentQuestionAnswers}"/>
>>>>                               </h:selectOneRadio>
>>>>                               <br>
>>>>                           </td>
>>>>                       </tr>
>>>>
>>>> You can see that each time I want a list of answers I call the
>>>> currentQuestionAnswers method of the backing bean.  The page displays
>>>> correctly, and like stated above, the user can select an answer to one of
>>>> the questions, but if the user answers both questions there is a validation
>>>> error everytime.  Any ideas?  Help is greatly appreciated!
>>>>
>>>> - Scott
>>>>
>>>
>>>
>>
>

Reply via email to