PrimeFaces DataTable with required Radiobutton

I am using PrimeFaces DataTable with Radiobuttons inside one wizard tab. Is it possible to somehow install Radiobuttons as required ?

The user does not have to go to the next tab of the wizard until he selects one option in the DataTable using Radiobuttons.

Or do you have ideas how to solve this problem? Thanks for any answers!

JSP Page

<p:tab id="test" title="Test"> <p:panel header="Term page"> <p:dataTable id="collection" value="#{register.dataList}" var="dl" rowKey="#{dl.c_id}" selection="#{register.selectedTerm}""> <p:column selectionMode="single" style="width:2%" /> <p:column> #{dl.c_id} </p:column> </p:dataTable> </p:panel> </p:tab> 
+4
source share
1 answer

You can check the data selection in the flowListener tag <p:wizard> , which starts when you click the following / previous buttons and conditionally add FacesMessage :

 public String onFlowProcess(FlowEvent event) { String current = event.getOldStep(); String next = event.getNewStep(); boolean proceed = true; if(current.equals("first") && next.equals("second") && (selectedData == null)) { //proceed only when data was selected and user is moving to the next step FacesMessage facesMessage = new FacesMessage("You need to make a selection in a datatable to proceed!"); FacesContext.getCurrentInstance().addMessage("form:selection", facesMessage); proceed = false; } return proceed ? next : current; } 

A complete example is given below.

View:

 <h:form id="form"> <p:wizard widgetVar="wiz" flowListener="#{q16439053Bean.onFlowProcess}"> <p:tab id="first" title="First"> <p:message for="selection"/> <p:panel id="selection" header="Term page"> <p:dataTable id="collection" value="#{q16439053Bean.list}" var="data" rowKey="#{data.name}" selection="#{q16439053Bean.selectedData}"> <p:column selectionMode="single" style="width:2%" /> <p:column> #{data.name} </p:column> </p:dataTable> </p:panel> </p:tab> <p:tab id="second" title="Second"> Done! </p:tab> </p:wizard> </h:form> 

bean:

 @ManagedBean @ViewScoped public class Q16439053Bean implements Serializable { private List<Data> list; private Data selectedData; public List<Data> getList() { return list; } public void setList(List<Data> list) { this.list = list; } public Data getSelectedData() { return selectedData; } public void setSelectedData(Data selectedData) { this.selectedData = selectedData; } public class Data { private String name; private String value; public Data() { } public Data(String name, String value) { this.name = name; this.value = value; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getValue() { return value; } public void setValue(String value) { this.value = value; } } public Q16439053Bean() { list = new ArrayList<Data>(); Data d; d = new Data("name", "value"); list.add(d); d = new Data("name1", "value1"); list.add(d); d = new Data("name2", "value2"); list.add(d); d = new Data("name3", "value3"); list.add(d); } public String onFlowProcess(FlowEvent event) { String current = event.getOldStep(); String next = event.getNewStep(); boolean proceed = true; if(current.equals("first") && next.equals("second") && (selectedData == null)) { FacesMessage facesMessage = new FacesMessage("You need to make a selection in a datatable to proceed!"); FacesContext.getCurrentInstance().addMessage("form:selection", facesMessage); proceed = false; } return proceed ? next : current; } } 
+1
source

Source: https://habr.com/ru/post/1479719/


All Articles