Filter
For a small amount of options, icon-based filters can be used and integrated in the table or column header.
<h:form id="fHeader">
<p:dataTable styleClass="jeesl-datatable"
var="j" value="#{tableFilterBean.jobsTable}">
<f:facet name="header">
<j:dtHeader title="Header">
<jp:thFilter handler="#{tableFilterBean.thFilter}" header="true"/>
</j:dtHeader>
</f:facet>
<p:column styleClass="jeeslCenter" headerText="#{msg.jeeslJobStatus}">
<jtp:symbolizer value="#{j.status}"/>
</p:column>
<p:column headerText="#{msg.jeeslName}">
<h:outputText value="#{j.name}"/>
</p:column>
</p:dataTable>
</h:form>
<h:form id="fColumn">
<p:dataTable styleClass="jeesl-datatable"
var="j" value="#{tableFilterBean.jobsColumn}">
<f:facet name="header">
<j:dtHeader title="Column"/>
</f:facet>
<p:column styleClass="jeeslCenter">
<f:facet name="header">
<jp:thFilter handler="#{tableFilterBean.chFilter}"/>
</f:facet>
<jtp:symbolizer value="#{j.status}"/>
</p:column>
<p:column filterBy="#{j.name}" filterMatchMode="contains" filterStyle="#{appSettingsBean.filterStyle35}">
<f:facet name="header">
<jtp:label entity="SystemJob" code="name"/>
<br/><h:outputText value="#{appSettingsBean.filterStyle35}"/>
</f:facet>
<h:outputText value="#{j.name}"/>
</p:column>
</p:dataTable>
</h:form>
@Named @ViewScoped
public class TableFilterBean extends AbstractJeeBean implements ThMultiFilterBean
{
final static Logger logger = LoggerFactory.getLogger(TableFilterBean.class);
private static final long serialVersionUID = 1L;
private final ThMultiFilterHandler<SystemJobStatus> thFilter;
public ThMultiFilterHandler<SystemJobStatus> getThFilter() {return thFilter;}
private final ThMultiFilterHandler<JeeGraphicWithName> th2;
public ThMultiFilterHandler<JeeGraphicWithName> getTh2() {return th2;}
private final ThMultiFilterHandler<SystemJobStatus> chFilter;
public ThMultiFilterHandler<SystemJobStatus> getChFilter() {return chFilter;}
private final Random rnd;
private List<SystemJob> jobsAll;
private final List<SystemJob> jobsTable; public List<SystemJob> getJobsTable() {return jobsTable;}
private final List<SystemJob> jobsColumn; public List<SystemJob> getJobsColumn() {return jobsColumn;}
private final List<JeeGraphicWithName> names; public List<JeeGraphicWithName> getNames() {return names;}
public TableFilterBean()
{
thFilter = new ThMultiFilterHandler<>(this);
th2 = new ThMultiFilterHandler<>(this);
chFilter = new ThMultiFilterHandler<>(this);
rnd = new Random();
jobsTable = new ArrayList<>();
jobsColumn = new ArrayList<>();
names = new ArrayList<>();
}
@PostConstruct public void init()
{
super.initSecurity();
thFilter.setList(fUtils.all(SystemJobStatus.class));
thFilter.selectAll();
names.addAll(fUtils.all(JeeGraphicWithName.class));
th2.setList(names);
th2.selectAll();
chFilter.setList(fUtils.all(SystemJobStatus.class));
chFilter.selectAll();
jobsAll = new ArrayList<>();
for(int i=0;i<10;i++)
{
SystemJobStatus status = thFilter.getList().get(rnd.nextInt(thFilter.getList().size()));
jobsAll.add(JeeFactoryProvider.job().job().build(null,null,status,""+i,"Job: "+i,null));
}
filter();
}
@Override public void filtered(ThMultiFilter filter) throws JeeslLockingException, JeeslConstraintViolationException
{
logger.info("Received "+filter.getClass().getSimpleName());
if(filter.equals(thFilter)) {filter();}
else if(filter.equals(chFilter)) {filter();}
}
private void filter()
{
jobsTable.clear();
jobsColumn.clear();
for(SystemJob job : jobsAll)
{
if(thFilter.getSelected().contains(job.getStatus())){jobsTable.add(job);}
if(chFilter.getSelected().contains(job.getStatus())){jobsColumn.add(job);}
}
}
}
Name | Required | Default | Description |
---|---|---|---|
handler | true | A ThMultiFilterHandler for handling a list of option and the selected ones. | |
update | false | @form | |
process | false | @this | |
immediate | false | true | |
height | false | 12 | |
styleClass | false | 12 | |
header | false | false | If used inside j:dtHeader, it need to be true. In columns the default=false can be used. |
showTooltipFromListName | false | false | Show tool tip using list name attribute |