tags:

views:

87

answers:

1

I have a list of questions and I can display them ok using a ui:repeat, but after clicking the Edit button the rerendered inputText is given the wrong question.id. For some reason, if you click Edit on the first item, the inputText value assigned is that of the second item in the list, even though other outputs (other than the h:inputText element) are correct.

   <h:form id="questionnaireForm">

        <ui:repeat value="#{ProjectManager.currentProject.preQuestions}" var="question" varStatus="current"
                   id="preQuestionsRepeat">
            <div>
                <ui:fragment rendered="#{!question.editing}">
                    <f:ajax render="@form">
                        <p>#{question.id} #{question.questionText}</p>
                        <h:inputText value="#{question.id}"/>
                        <h:commandLink styleClass="link"
                                       action="#{question.setEditing}"
                                       value="Edit">
                        </h:commandLink>
                    </f:ajax>
                </ui:fragment>
            </div>
            <div>
                <ui:fragment rendered="#{question.editing}">
                    <f:ajax render="@form">
                        <p>#{question.id} #{question.questionText}</p>
                        <h:inputText value="#{question.id}"/>
                    </f:ajax>
                </ui:fragment>
            </div>
        </ui:repeat>

    </h:form>

Obviously I don't really want to edit the id. I just want the correct question.something to show up in my inputText :-)

Perhaps I'm not using correctly? It seems fine according to my reading so far.

Many thanks for your assistance.

+1  A: 

Did you correctly override equals() and hashCode()? These methods are used to pull the value from the list that you selected. It pulls the first one that matches with the equals() operator.

Brian Leathem
Thanks for this Brian. I tried your suggestion which sounded great, but it didn't make any difference unfortunately so we re-engineer the entire page to use jQuery and a servlet instead ;-)
Andrew