How to update an external element to p:datatable with selectionMode="single"

Asked

Viewed 82 times

0

I’m using the component p:dataTable of primefaces with selectionMode="single" using RadioButton as a selection.

I would like when selecting a table row to update my label with the value of the selected profile, but this does not occur.

<p:dataTable 
    id="gridControleAcesso" 
    var="perfil" reflow="true"
    rowIndexVar="index" 
    value="#{controleDeAcessoController.perfis}"
    selection="#{controleDeAcessoController.perfilSelecionado}"
    rowKey="#{perfil.id}"
    disabledSelection="#{controleDeAcessoController.usuario == null}"
    update="comboPrestadoresDeServicos"
    imediate="true"
    >
     <p:ajax event="rowSelect" update="labelTest" process="@form" imediate="true" />
     <p:column selectionMode="single" headerText="Acesso"  >

    </p:column>
    <p:column headerText="Perfil" >
        <h:outputText value="#{perfil.nome}" />
    </p:column> 
</p:dataTable>

<h:outputText id="labelTest" value="a:: #{controleDeAcessoController.perfilSelecionado.nome}" /> 

2 answers

1


I solved as follows, I added the class hide-radio-selection and created a class that removes the radio-button standard and created my own radio-button, as below

<p:dataTable 
    id="gridControleAcesso" 
    var="perfil" reflow="true"
    rowIndexVar="index" 
    value="#{controleDeAcessoController.perfis}"
    selection="#{controleDeAcessoController.perfilSelecionado}"
    rowKey="#{perfil.id}"
    disabledSelection="#{controleDeAcessoController.usuario == null}"
    update="comboPrestadoresDeServicos"
    imediate="true"
    >
     <p:column selectionMode="single" headerText="Acesso" styleClass="hide-radio-selection text-center"  >
<p:selectOneRadio  value="#{controleDeAcessoController.perfilSelecionado}" unselectable="true" disabled="#{controleDeAcessoController.usuario == null}">
                                <p:ajax event="change" update="@form" listener="#{controleDeAcessoController.atualizarSelecao()}" process="@this" />
                                <f:selectItem itemLabel="" itemValue="#{perfil}" />
                            </p:selectOneRadio>
    </p:column>
    <p:column headerText="Perfil" >
        <h:outputText value="#{perfil.nome}" />
    </p:column> 
</p:dataTable>

0

Hello!

I don’t know if this is the case, but based on the code you put, I believe it may be the question of how the element id is formed when the page is rendered.

For example:

If your view looks like this:

<h:form id="formulario">
     <h:outputText id="labelTest" value="a:: #controleDeAcessoController.perfilSelecionado.nome}" />
</h:form>

Your label id will be generated in the following format:

id="formulario:labelTest"

You have two options to update the component: 1) Declares the form using prependId="false"

<h:form id="formulario" prependId="false"></h:form>

And then you can leave your update as is, or

2) In update you use the full path starting with ':'

<p:ajax event="rowSelect" update=":formulario:labelTest" process="@form" imediate="true" />

Another option is that when using the RadioButton, the event it fires is the rowSelectRadio and not the rowSelect.

  • Thanks for the, answer, but unfortunately the selectors did not solve my problem

Browser other questions tagged

You are not signed in. Login or sign up in order to post.