Board index JavaServer Faces General PrimeUI generating repeated IDs for selectBooleanCheckbox

PrimeUI generating repeated IDs for selectBooleanCheckbox

Components, Ajax Framework, Utilities and More.


Posts: 3
Hello PrimeUI experts.

I have a issue with primefaces generating repeated IDs for checkboxes.
I have 2 guys, one with 2 tests and other with 4 tests.
When I list them using subTable (http://www.primefaces.org/showcase/ui/datatableSubTable.jsf) the ID that primefaces generates for each checkbox is based on the checkbox position under the person.
That means each first person test will have an ID as zero, the second as 1, the third as 2...

Below is an screenshot of the first test of each person being highlighted when I just pass the mouse over anyone of the first checkboxes.
Image
The same happens when I pass mouse over the second test checkbox, the checkbox that is in second position of each person is highlighted.

How can I generate dynamic checkbox IDs?

I tryied to set id="#{test.testId}" but all just crashes when I do that...

Is this a PrimeFaces bug?

XHTML code:
<p:dataTable id="sorotable"
                                     style="text-align: center; width: 806px; margin-top: 5px; margin-left: -15px !important;"
                                     rowKey="#{e.resExameCmDcId}"
                                     styleClass="list" tableStyleClass=" list2 list-table mg-leftless5"   
                                     value="#{cc.attrs.exameAccordion.exameCMDCBean.pessoasCMDC}" var="pessoaCMDC" paginator="false"
                                     emptyMessage="#{global['global.mensagem.vazio']}" >
                       
                            <p:columnGroup type="header"> 
                                <p:row> 
                                    <p:column headerText="Checkbox" /> 
                                    <p:column headerText="Soro" /> 
                                    <p:column headerText="PRA AGH c/DIT" /> 
                                    <p:column headerText="PRA AGH s/DIT" /> 
                                    <p:column headerText="PRA Quali I" /> 
                                    <p:column headerText="PRA Quali II" /> 
                                    <p:column headerText="PRA Quanti I" /> 
                                    <p:column headerText="PRA Quanti II" /> 
                                </p:row> 
                            </p:columnGroup>
                            <p:subTable id="subtable" var="exame" value="#{pessoaCMDC.exameCMDC}">
                                <f:facet name="header">
                                    <p:column style="text-align: center; min-width: 0px; width: 200px;">
                                        <h:outputText value="#{pessoaCMDC.nome} "/>
                                    </p:column>
                                    <p:column style="text-align: center; min-width: 0px; width: 70px">
                                        <h:outputText value="  - RGCT: #{pessoaCMDC.rgct} "/>
                                    </p:column>
                                </f:facet>

                               
                                <p:column style="text-align: center;">
                                    <p:selectBooleanCheckbox
                                                             value="#{exame.selected}"
                                                             disabled="#{(exame.resExameCmDcId==null?false:true) or (cc.attrs.exameAccordion.disableEdicao)}">
                                        <p:ajax listener="#{exameCMDCMBean.processSoroSelection}"  />
                                        <f:attribute name="selres" value="#{pessoaCMDC.exameCMDC}" />
                                        <f:attribute name="ex" value="#{cc.attrs.exameAccordion}" />
                                    </p:selectBooleanCheckbox>
                                   
                                </p:column>
                               
                                <p:column style="text-align: center;min-width: 0px; width: 120px">
                                    <h:outputText value="#{exame.soroId.nomeAmostra}"/>
                                </p:column>
                                <p:column style="text-align: center;min-width: 0px; max-width: 80px; min-width: 20px;"> 
                                    <h:outputText value="#{exame.praAghSemDTT}"/>
                                </p:column>
                                <p:column style="text-align: center;min-width: 0px; max-width: 80px; min-width: 20px;"> 
                                    <h:outputText value="#{exame.praAghComDTT}"/>
                                </p:column>
                                <p:column style="text-align: center;min-width: 0px; min-width: 20px;"> 
                                    <h:outputText value="#{exame.praQualiI}"/>
                                </p:column>
                                <p:column style="text-align: center;min-width: 0px; min-width: 20px;"> 
                                    <h:outputText value="#{exame.praQualiII}"/>
                                </p:column>
                                <p:column style="text-align: center;min-width: 0px; min-width: 20px;"> 
                                    <h:outputText value="#{exame.praQuantiI}"/>
                                </p:column>
                                <p:column style="text-align: center;min-width: 0px; min-width: 20px;"> 
                                    <h:outputText value="#{exame.praQuantiII}"/>
                                </p:column>
                            </p:subTable>
                           
                            <p:columnGroup type="footer"/>
                           
                           
                        </p:dataTable>
Last edited by dragongbr on 15 Jul 2013, 15:56, edited 1 time in total.


Posts: 3
I'm sure more people already had the same problem than me.
That is a basic thing in PrimeFaces.

If someone can help, I would be glad.

kukeltje Expert Member

Posts: 6406
Location: Netherlands
dragongbr wrote:
I'm sure more people already had the same problem than me.


Obviously not.
Ronald van Kuijk
______________________________
PrimeFaces 4.0, PrimeFaces plus 0.0.2 | Jboss 7.2.0 | Mojarra 2.1.18
Fedora 19, Firefox 26.0
Read the forum posting rules
Beginners: http://www.coreservlets.com/JSF-Tutorial/jsf2/


Posts: 433
Post your xhtml, version info, then others might be able to help you more. But two things are quite sure here:
I tryied to set id="#{test.testId}" but all just crashes when I do that...

This will most likely not work because of how ids are assigned and how iterating components work. You can Google for JSF dynamic id and you will probably get results for why it won't work.
Is this a PrimeFaces bug?

In 99,99999999% of cases it's not.

TLDR: post code and version infos.
Server: Wildfly 8.0.0
JSF: Mojarra 2.2.5
PF version: PrimeFaces 5.0 + Extensions 1.2.1
Other: OmniFaces 1.7.0
Browser: Firefox 2x


Posts: 3
I've posted the XHTML code of the part that is not working.

Did someone experienced the same issue? That is driving me crazy. :P


Posts: 5902
Evidently, you need to look at the PrimeFaces showcase example for Subtable, and use the 'same' code that you see in the showcase example, take that code, create a small test case (project) in your IDE, copy/paste the subtable showcase example code (xhtml and bean), and then add p:selectBooleanCheckbox (and keep it very very simple), and that will help you 'learn' how to use and add selectBooleanCheckbox to subtable, and then after you do this, come back here and let us know what changes you made to your code to get it working.

Of course, you better pay attention to everything in rikup's earlier response, and modify your code, accordingly.
Howard

PrimeFaces 5.1, Extensions 2.1.0, Push (Atmosphere 2.2.1)
TomEE+ 1.7.1 (Tomcat 7.0.55), MyFaces Core 2.2.5, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache


Return to General