coshikipix
coshikipix

Reputation: 59

PrimeFaces Slider 'for' value not working in a dataTable

Hello guys I'm trying to create a data table where people can set a value between 1 and 10 for each row:

<p:dataTable id="coteTable" value="#{editEvaluationView.evaluation.listCote}" var="cote">

        <p:column colspan="10">

            <p:inputText id="cote_#{cote.critere.code.trim()}"
                                    value="#{cote.valeur}" />
            <p:slider minValue="1" maxValue="10"
                                    for="cote_#{cote.critere.code.trim()}" />
        </p:column>

        <p:column>
                <p:inputText id="commmentaire" value="#{cote.observations}" />
        </p:column>
</p:dataTable>

But it doesn't recognize the id (cote_CRT001 is the first cote_#{cote.critere.code.trim()} value):

javax.servlet.ServletException: Cannot find component for expression "cote_CRT001" referenced from "formEditEval:coteTable:0:j_idt120".

I really don't know what to try anymore. Does anybody have an idea why it's not working?

Upvotes: 1

Views: 315

Answers (1)

Jasper de Vries
Jasper de Vries

Reputation: 20158

A dataTable is a naming container, so components within it will be prepended with the dataTable's id. Also, each iteration of data presented in the table (each row) will have effect of the generated ids. So there is no need for you to try to create unique ids. If you simply use cote of the inputText's id. Since a form is also a naming container, it will be generated as formId:coteTable:0:cote in the first row, formId:coteTable:1:cote in the second row, etc. In your slider you can simply use for="cote" because you are referencing a component in the same naming container.

So, simply write:

<p:dataTable id="coteTable" value="#{editEvaluationView.evaluation.listCote}" var="cote">
    <p:column colspan="10">
        <p:inputText id="cote" value="#{cote.valeur}" />
        <p:slider minValue="1" maxValue="10" for="cote" />
    </p:column>
    ...
</p:dataTable>

See also

Upvotes: 1

Related Questions