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

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?

Related

How to filter dataTable items?

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").

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>

How to display the values in open faces datatable?

Actually i am using open faces data table for selecting rows using the attribute < o:checkboxColumn rowDatas will automatically filter the currently selected rows .I didn't do any filter in Bean file,the selected list values are stored in my database table .My problem is how to display the selected list to other data table , if i did iteration only the values will be display (there is no need of iteration here ).
<o:dataTable id="type_parts_table"
value="#{employeeBean.srNameList}"
applyDefaultStyle="true" var="type_parts" width="600px"
pageSize="10" headerRowClass="header-table-row"
bodyRowClass="normal-table-row"
bodySectionClass="normal-table-row"
sortedColumnHeaderClass="sorted-header-row">
<o:column width="200px">
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{type_parts.name}" />
</o:column>
<o:column width="200px">
<f:facet name="header">
<h:outputText value="Type" />
</f:facet>
<h:outputText value="#{type_parts.head}" />
</o:column></o:dataTable>
Is there any attribute to display those values .

Resources