
|
selectOneRadio validation error
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
|

|
RE: selectOneRadio validation error

Some parts of this message have been removed.
Learn more about Nabble's security policy.
Have you looked at layout=spread and see
if that would help.
From: Scott Carter
[mailto:carterdevlists@...]
Sent: Thursday, June 25, 2009 5:15
PM
To: users@...
Subject: selectOneRadio validation
error
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
|

|
Re: selectOneRadio validation error
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 <carterdevlists@...> 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
|

|
Re: selectOneRadio validation error
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 <sam72wong@...> 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 <carterdevlists@...> 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
|

|
Re: selectOneRadio validation error
How about the setter? On Fri, Jun 26, 2009 at 9:52 AM, Scott Carter <carterdevlists@...> 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 timeOn Fri, Jun 26, 2009 at 10:33 AM, Sam <sam72wong@...> 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 <carterdevlists@...> 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
|

|
Re: selectOneRadio validation error
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 <sam72wong@...> wrote:
How about the setter?On Fri, Jun 26, 2009 at 9:52 AM, Scott Carter <carterdevlists@...> 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 timeOn Fri, Jun 26, 2009 at 10:33 AM, Sam <sam72wong@...> 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 <carterdevlists@...> 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
|

|
Re: selectOneRadio validation error
Sorry, my mistake. What's the stacktrace on your validation error? On Fri, Jun 26, 2009 at 10:05 AM, Scott Carter <carterdevlists@...> wrote:
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 <sam72wong@...> wrote:
How about the setter?On Fri, Jun 26, 2009 at 9:52 AM, Scott Carter <carterdevlists@...> 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 timeOn Fri, Jun 26, 2009 at 10:33 AM, Sam <sam72wong@...> 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 <carterdevlists@...> 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
|

|
Re: selectOneRadio validation error
Just for kicks, could you change your getter to return a List<SelectItem> instead of SelectItem[]? On Fri, Jun 26, 2009 at 10:10 AM, Sam <sam72wong@...> wrote:
Sorry, my mistake. What's the stacktrace on your validation error?
On Fri, Jun 26, 2009 at 10:05 AM, Scott Carter <carterdevlists@...> wrote:
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 <sam72wong@...> wrote:
How about the setter?On Fri, Jun 26, 2009 at 9:52 AM, Scott Carter <carterdevlists@...> 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 timeOn Fri, Jun 26, 2009 at 10:33 AM, Sam <sam72wong@...> 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 <carterdevlists@...> 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
|

|
Re: selectOneRadio validation error
There is not a stack trace shown in the log. The see the errors on the page from the <h:messages> tag. The errors on the page look like the following: - mainForm:q1answers: Validation Error: Value is not valid
- mainForm:q4answers: Validation Error: Value is not valid
- mainForm:q5answers: Validation Error: Value is not valid
I changed the method to return a list instead of an array and got the same result. Any other ideas on what this could be? Here is the new method which returns the list:
public List<SelectItem> getCurrentQuestionAnswers() { Question currentQuestion = this.questionList.get(questionCount); int qWeight = currentQuestion.getQuestionWeight();
List<SelectItem> answers = new ArrayList<SelectItem>(); answers.add(new SelectItem(Integer.toString(qWeight) , "SA")); answers.add(new SelectItem(Integer.toString(qWeight - (qWeight / 5)) , "A"));
answers.add(new SelectItem(Integer.toString(qWeight - ((qWeight / 5) * 2)), "N")); answers.add(new SelectItem(Integer.toString(qWeight - ((qWeight / 5) * 3)) , "D")); answers.add(new SelectItem(Integer.toString(qWeight - ((qWeight / 5) * 4)) , "SD"));
this.questionCount++; return answers; } On Fri, Jun 26, 2009 at 11:12 AM, Sam <sam72wong@...> wrote:
Just for kicks, could you change your getter to return a List<SelectItem> instead of SelectItem[]?
On Fri, Jun 26, 2009 at 10:10 AM, Sam <sam72wong@...> wrote:
Sorry, my mistake. What's the stacktrace on your validation error?
On Fri, Jun 26, 2009 at 10:05 AM, Scott Carter <carterdevlists@...> wrote:
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 <sam72wong@...> wrote:
How about the setter?On Fri, Jun 26, 2009 at 9:52 AM, Scott Carter <carterdevlists@...> 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 timeOn Fri, Jun 26, 2009 at 10:33 AM, Sam <sam72wong@...> 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 <carterdevlists@...> 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
|