Row Selection
If multiple selection is active, the rowSelect AJAX event should not target the current data table, otherwise selection with SHIFT will not work.
<h:form id="fTable">
<p:dataTable id="dt" styleClass="jeesl-datatable"
var="r" value="#{tableRowSelectionBean.rows}"
selection="#{tableRowSelectionBean.selection}" selectionMode="multiple" rowKey="#{r.id}">
<f:facet name="header">
<j:dtHeader id="dth" title="p:dataTable">
<p:outputPanel id="dthOp">
<j:svg type="jeeslArrowRight" rendered="#{not empty tableRowSelectionBean.selection}"
listener="#{tableRowSelectionBean.moveSelection()}" update="@form"/>
</p:outputPanel>
</j:dtHeader>
</f:facet>
<p:ajax event="rowSelect" listener="#{tableRowSelectionBean.selectElements()}" update=":fTable:dt:dth:dthOp"/>
<p:column rendered="true">
<h:outputText value="#{r.name[localeCode].lang}"/>
</p:column>
</p:dataTable>
</h:form>
@Named @ViewScoped
public class TableRowSelectionBean extends AbstractJeeBean implements Serializable
{
final static Logger logger = LoggerFactory.getLogger(TableRowSelectionBean.class);
private static final long serialVersionUID = 1L;
private List<IoFileType> rows; public List<IoFileType> getRows() {return rows;}
private List<IoFileType> selection;
public List<IoFileType> getSelection() {return selection;}
public void setSelection(List<IoFileType> selection) {this.selection = selection;}
@PostConstruct
public void init()
{
super.initSecurity();
rows = fUtils.all(IoFileType.class);
}
public void selectElements() throws JeeslNotFoundException
{
logger.info(JeeLogMessage.selectEntities(IoFileType.class, selection));
}
public void moveSelection() throws JeeslNotFoundException
{
logger.info(JeeLogMessage.selectEntities(IoFileType.class, selection));
if(ObjectUtils.isNotEmpty(selection))
{
for(IoFileType t : selection)
{
rows.remove(t);
}
selection.clear();
}
}
}