How to filter dataTable items? - jsf

Problem
When creating a dataTable using Bootfaces, I can bring all items of my DB but I need to bring just the ones which field equals a specific number. ¿How can I do that?
Example
Evento (Id, nombre, categoria)
Id Nombre Categoria
1 aaaa 1
2 bbbb 2
3 cccc 2
dataTable only brings the first one, Id 1.
Code
<b:dataTable value="#{eventoController.items}" var="item" styleClass="list" scroll-x="true">
<h:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListEventoTitle_idEvento}"/>
</f:facet>
<h:outputText value="#{item.idEvento}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListEventoTitle_nombre}"/>
</f:facet>
<h:outputText value="#{item.nombre}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListEventoTitle_idCategoria}"/>
</f:facet>
<h:outputText value="#{item.idCategoria}"/>
</h:column>
</b:dataTable>

Replace the <h:column> by it's BootsFaces counterpart <b:dataTableColumn />. Now you can set the attribute search-value. Most likely you also need to activate multi-column-search='true'and s searching='true'. In your case, that's
<b:dataTable value="#{eventoController.items}"
var="item"
styleClass="list"
scroll-x="true"
multi-column-search="true"
searching="true">
<b:dataTableColumn search-value="1" searchable="true">
<f:facet name="header">
<h:outputText value="#{bundle.ListEventoTitle_idEvento}"/>
</f:facet>
<h:outputText value="#{item.idEvento}"/>
</b:dataTableColumn>
...
</b:dataTable>
Please keep in mind that the BootsFaces dataTable is a client-side widget. This means that the entire HTML table is sent to the client. That, in turn, makes for fast filtering, pagination, and sorting once the data has been loaded, but if you've got a huge amount of data, you'll want to filter the data on the server side, too.
Also see https://showcase.bootsfaces.net/forms/DataTable.jsf (search for "initial search filter").

Related

How to get multiple h:selectOneMenu values inside h:dataTable [duplicate]

This question already has answers here:
Input field in <h:dataTable> always receives value of last item in list
(3 answers)
Closed 7 years ago.
I'm using h selectOneMenu in a datatable and when user press the Set Fixture button i'm saving the value changed in the dropdown, for now i'm using a String variable to get the selected value but the issue is it have the selected value from only the last dropdown. My question is how to get list of all the dropdowns ?
<h:form id="chooseAlmFixtureForm">
<p:panel style="width:80%" header="Set Fixture for Alarms">
<p:dataTable id="tbsetFixtureTable" value="#{setAlmFixtures.alarms}" var="alarmvar" dynamic="false">
<p:column>
<p:commandLink value="View" update=":viewUnknownAlarm" immediate="true" oncomplete="viewDialog.show()">
<f:setPropertyActionListener target="#{currentalarms.viewAlarm}" value="#{alarmvar}"/>
</p:commandLink>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Alarm Time"/>
</f:facet>
<h:outputText value="#{alarmvar.recvTime}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Alarm Type"/>
</f:facet>
<h:outputText value="#{alarmvar.alarmType}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Controller Name"/>
</f:facet>
<h:outputText value="#{alarmvar.controllerName}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Controller Type"/>
</f:facet>
<h:outputText value="#{alarmvar.controllerType}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Choose Fixture"/>
</f:facet>
<h:selectOneMenu id="selectAlarmSite" value="#{setAlmFixtures.selectedFixture}">
<f:selectItems value="#{setAlmFixtures.fixtures}" />
</h:selectOneMenu>
</p:column>
</p:dataTable>
<p:commandButton value="Set Fixtures" actionListener="#{setAlmFixtures.setAlarmsFixtures}" action="#{horizontalmenu.actionCallAlarmsPage}" styleClass="dialogButton"/>
</td><td>
<p:commandButton value="Cancel" actionListener="#{setAlmFixtures.releaseAlarms}" action="#{horizontalmenu.actionCallAlarmsPage}" styleClass="dialogButton"/>
</p:panel>
</h:form>
Currently, your dropdown-value refers to a single variable in your bean (which seems to be selectedFixture of class SetAlmFixtures). How would a single variable represent a state (value) for multiple row (here: alarms)?
You need to link the selected value to the row (alarm) it refers to. To do so, you have several options, two approaches following:
Use the variable of your alarm-object, just the same way as you used them as outputvalues inside the other columns. This way, the alarm's fixture is set directly on value (form) processing. Currently, both of your buttons submit the form (type="submit" is default), depending on what your actionlisteners do, you might consider changing the Cancel-button's type to button.
Map the fixtures and alarms. You could use something like Map<Long, Fixture> fixturemap; mapping alarm-id's to their selected fixture, assuming all alarms have a non-null id. The map's value can be referred by setAlmFixtures.fixturemap['alarmvar.id']. Make sure you provide a getter for the map and the id. Also, you need to initialize the map with the initial fixture values for each alarm.

How to render a specific row in richfaces 4?

I have the following DataTable in richFaces 4.5.2:
<rich:dataTable id="t" var="v" rows="#{bean.size}"
value="#{bean.value}" rowKeyVar="row">
<rich:column>
<a4j:commandLink action="#{bean.doAction}" render="t:#{row}">
<h:outputText value="#{recipientGroup.id}" />
<f:facet name="footer">
<h:outputText value="#{msgs['dynamicRecipientGroupList.table.id']}"/>
</f:facet>
</rich:column>
</rich:dataTable>
I thought specifying the rowId explicitly force the richFaces to render the only specified row, but It renders the whole table instead. What did I do wrong?
New syntax is described here. (All data iteration components)
In your case it should be something like:
render="t:#rows(row)"

Iterating two lists in a <rich:datatable> using <a4j:repeat>

I have two List<String> and I'd like to put them in one <rich:datatable>, each List<String> should be a column on the <rich:datatable>. I'm trying to do that using <a4j:repeat>, but when I execute the program, only the headers of the <rich:datatable> appear, no content is shown on the <rich:datatable> .
Look at the code:
<rich:dataTable>
<rich:column>
<f:facet name="header">URI</f:facet>
<a4j:repeat value="#{pesquisaBean.documentUriByTitleList}" var="uri">
#{uri}
</a4j:repeat>
</rich:column>
<rich:column>
<f:facet name="header">Subject</f:facet>
<a4j:repeat value="#{pesquisaBean.subjectByTitleList}" var="sub">
#{sub}
</a4j:repeat>
</rich:column>
</rich:dataTable>
What's the problem?
Thank you!
The datatable can iterate through a list on its own, the repeat doesn't belong there. You should combine the lists into one (since I am assuming there is a relation between the URI and subject) and let the table iterate through that list. (i.e. you create an object that contains a URI and a subject and put it in a list)
<rich:dataTable value="#{bean.list}" var="item">
<rich:column>
<f:facet name="header">URI</f:facet>
#{item.uri}
</rich:column>
<rich:column>
<f:facet name="header">Subject</f:facet>
#{item.sub}
</rich:column>
</rich:dataTable>

<rich:extendedDataTable> <c:forEach> Displaying a table via a "Map of maps"

I have a data model with structure : TreeMap < String, TreeMap< String, Double>> resultMap;
This is stored in a SessionScoped ManagedBean.
I am trying to output this via a dynamic < rich:extendedDataTable> where;
Key of first map is the row label
Value of first map is a second map ( corresponds to the columns on the row
Key of second map is the columns header
Value of second map is the columns value
Source Code:
<rich:extendedDataTable
value="#{queryBean.resultMap.keySet().toArray()}" var="key"
frozenColumns="1" styleClass="rich-extdt">
<rich:column width="75px">
<f:facet name="header">
<h:outputText value="Mediation" />
</f:facet>
<h:outputText value="#{key}" />
</rich:column>
<rich:column width="75px">
<f:facet name="header">
<h:outputText value="Test" />
</f:facet>
<h:outputText value="#{queryBean.resultMap[key]}" />
</rich:column>
<c:forEach items="#{queryBean.resultMap[key]}" var="map">
<rich:column width="75px">
<f:facet name="header">
<h:outputText value="#{map.key}" />
</f:facet>
<h:outputText value="#{map.value}" />
</rich:column>
</c:forEach>
</rich:extendedDataTable>
Output:
The first column is correctly outputting the keys of the first map.
The second column (used for debugging) is correctly outputting the map structure ( when I apply .keySet() to the structure I do get all the correct keys ).
Using: jstl 1.2.0, jsf 2.1 - mojarra, richfaces 4.x, tomcat 7.
Update:
As stated here, the < c:forEach> has no access to the < rich:dataTable> attributes, hence unable to use key. Is there any simple workaround to this?

How can I make p:cellEditor conditional in PrimeFaces?

Here is my code that doesn't work:
...
<p:column sortBy="#{invoice.customerId}" id="customerId">
<f:facet name="header"><h:outputText value="Customer ID"/></f:facet>
<f:facet name="output" rendered="#{!editUIBean.isEditable('customerId')}">
<h:outputText value="#{invoice.customerId}"/>
</f:facet>
<p:cellEditor rendered="#{editUIBean.isEditable('customerId')}">
<f:facet name="output">
<h:outputText value="#{invoice.customerId}"/>
</f:facet>
<f:facet name="input">
<h:inputText value="#{invoice.customerId}"/>
</f:facet>
</p:cellEditor>
</p:column>
...
So what I am trying to do: The user picks an option, that option determines which records are editable and only displays the records that are editable for that option. For any given option, only certain columns within those records are editable. The isEditable(columnName) method returns true if for given option the column is editable or false if it is not editable. What I want to do is, when the user clicks edit for the record, the editable fields display input fields and then non-editable fields display their values. With the code above, when the column isn't editable, the value doesn't display, before and after clicking edit. When the field is editable, the value displays, and when you click edit, the value is replaced with an input field containing the value. So my example works except that the value is completely hidden when the field is not editable. I want the non-editable values to be displayed when not editing and when editing, I just don't want them to be editable during edit.
This,
<p:column>
<f:facet name="output" rendered="#{!editUIBean.isEditable('customerId')}">
<h:outputText value="#{invoice.customerId}" />
</f:facet>
...
</p:column>
is not right. The <p:column> doesn't support a <f:facet name="output">. Just put the rendered condition on the <h:outputText> itself.
<p:column>
<h:outputText value="#{invoice.customerId}" rendered="#{!editUIBean.isEditable('customerId')}" />
...
</p:column>

Resources