开发者

RadioButton row select event in p:datatable

开发者 https://www.devze.com 2023-03-05 23:02 出处:网络
RadioButton/Checkbox based row selection is a common use case and DataTable provides a solution for this with column selection mode feature.

RadioButton/Checkbox based row selection is a common use case and DataTable provides a solution for this with column selection mode feature.

<p:dataTable var="car" value="#{tableBean.cars}" paginator="true" rows="10"
                 selection="#{tableBean.selectedCar}">`
     <f:facet name="header">
            RadioButton Based Selection
        </f:facet>

        <p:column selectionMode="single" />

        <p:column headerText="Model">
            <h:outputText value="#{car.model}" />
        </p:column>

        <p:column headerText="Year">
            <h:outputText value="#{car.year}" />
        </p:column>

        <p:column headerText="Manufacturer">
            <h:outputText value="#{car.manufacturer}" />
        </p:column>


        <f:facet name="footer">
            <p:commandButton value="View" image="ui-icon ui-icon-search"
                             update="displaySingle" oncomplete="singleCarDialog.show()"/>
        </f:facet>
    </p:dataTable>

I want to know if I choose the first column's radioButton ,how I get a event for this.

  • Because I want to let 开发者_Go百科a button disabled when choose the first column or the last column's radioButton .
  • And I also want to get the index of the column when selected the column ,Now I use the selectedCar to compare the list,and get the index of the column. It looks ugly.Anyone can help me ?


This is a solution for PrimeFaces <= 2.x only.

There is a good example at Primeface's showcase. There is an attribute rowSelectListener that can be used like this:

rowSelectListener="#{tableBean.onRowSelect}"

and in the backing bean:

public void onRowSelect(SelectEvent event) {  
        FacesMessage msg = new FacesMessage("Car Selected", 
                           ((Car) event.getObject()).getModel());  
        FacesContext.getCurrentInstance().addMessage(null, msg);  
}  
0

精彩评论

暂无评论...
验证码 换一张
取 消