【发布时间】:2021-08-31 06:02:39
【问题描述】:
我想禁用 PrimeFaces v8.0 数据表中的选择,但显示之前选择的值。
这是我的最小示例项目
<?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");
}
}
显示的表格是这样的
Disabled selection in PrimeFaces data table
我想要的是,单选按钮被禁用,但为了显示所选值“6”,我在后端 bean 中进行了选择。
有没有办法让它工作?
【问题讨论】:
标签: jsf primefaces