You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Richard Wallace <rw...@thewallacepack.net> on 2005/07/13 00:12:56 UTC
dataList with radio buttons
Hello,
I've got a dataList bound to a list of values in the backing bean as such:
<x:dataList id="questionList" layout="simple"
value="#{assessmentHandler.currentPage.questions}" var="question">
<h:outputText value="#{question.questionNo}.
#{question.text}" />
<f:verbatim><br /></f:verbatim>
<h:selectOneRadio id="choices" required="true"
value="#{assessmentHandler.responses[question.questionNo - 1].score}">
<f:selectItem id="oftenChoice"
itemValue="#{assessmentHandler.oftenScore}"
itemLabel="#{labels.oftenLabel}" />
<f:selectItem id="sometimesChoice"
itemValue="#{assessmentHandler.sometimesScore}"
itemLabel="#{labels.sometimesLabel}" />
<f:selectItem id="seldomChoice"
itemValue="#{assessmentHandler.seldomScore}"
itemLabel="#{labels.seldomLabel}" />
</h:selectOneRadio>
</x:dataList>
The assessmentHandler has the method getResponses() which returns a List
of Response objects. The Response objects has a getter/setter for the
score attribute. However, when I click the command button to advance to
the next page or to finish the questioning the Response objects score
values in the backing list is not updated with the value of the select
item. The required="true" attribute also seems to be ignored, because I
can safely advance without any errors. Is this not the right way to do
something like this?
I've looked at the list and the only alternative is to use Bruno
Aranda's valueChangeListener solution from the "is it possible to edit
dynamic Tabular data?" thread. But, as was stated in that thread, it
seems like the way I'm doing it should work to update the data model. I
don't need to implement a setResponses() method do I? The setScore()
method on the actual Response object should be enough, shouldn't it be?
I'm sure I don't need to use the preserveDataModel attribute or an
<x:saveState /> element. So what's missing?
Thanks,
Rich
Re: dataList with radio buttons
Posted by Richard Wallace <rw...@thewallacepack.net>.
Weird, I changed from <x:dataList> to <x:dataTable> and validation and
updating the data model works as it should. It's too bad cause I'd
rather not have to use a table for page layout. Using the list would
allow my designer to use <div> tags. Is this a bug or something that
the <x:dataList> isn't meant to be used for?
Thanks,
Rich
Richard Wallace wrote:
> Hello,
>
> I've got a dataList bound to a list of values in the backing bean as
> such:
>
> <x:dataList id="questionList" layout="simple"
> value="#{assessmentHandler.currentPage.questions}" var="question">
> <h:outputText value="#{question.questionNo}.
> #{question.text}" />
> <f:verbatim><br /></f:verbatim>
> <h:selectOneRadio id="choices" required="true"
> value="#{assessmentHandler.responses[question.questionNo - 1].score}">
> <f:selectItem id="oftenChoice"
> itemValue="#{assessmentHandler.oftenScore}"
> itemLabel="#{labels.oftenLabel}" />
> <f:selectItem id="sometimesChoice"
> itemValue="#{assessmentHandler.sometimesScore}"
> itemLabel="#{labels.sometimesLabel}" />
> <f:selectItem id="seldomChoice"
> itemValue="#{assessmentHandler.seldomScore}"
> itemLabel="#{labels.seldomLabel}" />
> </h:selectOneRadio>
> </x:dataList>
>
> The assessmentHandler has the method getResponses() which returns a
> List of Response objects. The Response objects has a getter/setter
> for the score attribute. However, when I click the command button to
> advance to the next page or to finish the questioning the Response
> objects score values in the backing list is not updated with the value
> of the select item. The required="true" attribute also seems to be
> ignored, because I can safely advance without any errors. Is this not
> the right way to do something like this?
> I've looked at the list and the only alternative is to use Bruno
> Aranda's valueChangeListener solution from the "is it possible to edit
> dynamic Tabular data?" thread. But, as was stated in that thread, it
> seems like the way I'm doing it should work to update the data model.
> I don't need to implement a setResponses() method do I? The
> setScore() method on the actual Response object should be enough,
> shouldn't it be? I'm sure I don't need to use the preserveDataModel
> attribute or an <x:saveState /> element. So what's missing?
>
> Thanks,
> Rich
Re: dataList with radio buttons
Posted by De...@ak.blm.gov.
Was immediate="true" in the dataTable element?
Re: dataList with radio buttons
Posted by Richard Wallace <rw...@thewallacepack.net>.
Dennis_Byrne@ak.blm.gov wrote:
>
> Can you please elaborate on "The required="true" attribute also seems
> to be ignored, because I
> can safely advance without any errors."?
I simply meant that if I clicked on a command button, such as "Next" or
"Finish" that MyFaces happily accepts the input as even if nothing is
filled in on the form, completely bypassing the validation. But, it
doesn't update the data model. At least, it doesn't update the data
model if <x:dataList> is used. It does if <h:dataTable> is used. If
dataTable is used everything works as it should.
Rich
Re: dataList with radio buttons
Posted by De...@ak.blm.gov.
Can you please elaborate on "The required="true" attribute also seems to
be ignored, because I
can safely advance without any errors."?