I want to disable the selection in a PrimeFaces v8.0 data table, but show the previously selected value.
This is my minimal example project
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xml:lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Disable table selection</title>
</h:head>
<h:body>
<h:form>
<h:panelGrid columns="1">
<p:dataTable var="value"
value="#{disabledTableSelectionBean.values}"
selection="#{disabledTableSelectionBean.selectedValue}"
disabledSelection="true"
rowKey="#{value}">
<p:column selectionMode="single" width="15" />
<p:column headerText="Value">
<h:outputText value="#{value}" />
</p:column>
</p:dataTable>
</h:panelGrid>
</h:form>
</h:body>
</html>
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
@Named
@ViewScoped
public class DisabledTableSelectionBean implements Serializable {
private List<String> values;
private String selectedValue = "6";
@PostConstruct
public void initialize() {
values = Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
}
}
The displayed table looks like this
Disabled selection in PrimeFaces data table
What I want is, that the radio buttons are disabled, but to show the selected value "6", I selected in the backend bean.
Is there a way to make this work?