<rich:dataTable> from listOfMaps - jsf-2

I have a SessionScoped bean which has a list of maps. I am attempting to get a <rich:dataTable> produced using <a4j:repeat>.
The list of maps is being populated correctly, although there is no dataTable output. From reading articles on stack-overflow, I think my problem may be occuring due to the life-cycle problems or my novice understanding of jsf with richfaces.
Using: Tomcat 7, JSF 2.1x - Mojarra, Richfaces 4.x
Here is what I have so far;
<rich:dataTable value="#{myBean.myMap}" var="map">
<a4j:repeat value="#{myBean.myMap[0].keySet().toArray()}" var="key">
#{map[key]}
</a4j:repeat>
</rich:dataTable>
If someone could point my in the correct direction, the help would be greatly appreciated!
Answer:
As stated below the solution is to instead use <c:forEach> and use <rich:columns>.
Solution:
<rich:dataTable value="#{queryBean.test}" var="map">
<c:forEach items="#{queryBean.test[0].keySet().toArray()}" var="key">
<rich:column style="text-align:left; width:auto;">
<f:facet name="header">
<h:outputText value="#{key}" />
</f:facet>
<h:outputText value="#{map[key]}" />
</rich:column>
</c:forEach>
</rich:dataTable>

First of all <rich:dataTable> has to contain columns - <rich:column>
Assuming you want to have dynamic table (the number of columns based on the length of the map) you will have to use <c:forEach> instead of <a4j:repeat>. I have answered a question about this a while ago, take a look.

Related

Using Tomahawk dataTable and varDetailToggler, I want a fixed header with scrollable rows

I've looked at other solutions for this problem, but they all seem to suggest using rich:scollableDataTable or rich:extendedDataTable. Neither of those provide the varDetailToggler functionality.
I've also seen a solution which splits the header into a separate table. Unfortunately, this solution breaks the use of varDetailToggler as well. The header contains buttons for ExpandAll and CollapseAll for the details.
Is there a Tomahawk solution?
Here's my solution:
<t:dataTable id="data" var="phen"
value="#{workflowLookup.dataModel}"
binding="#{workflowLookup.table}"
varDetailToggler="detailToggler">
<f:facet name="header">
<h:commandButton
id="expand-all-button"
action="#{detailToggler.expandAllDetails}"
value="Expand All" />
<h:commandButton
id="collapse-all-button"
action="#{workflowLookup.collapseAllDetails}"
value="Collapse All" />
</f:facet>
... (rest of table)
</t:dataTable>

primefaces : how to disable html escape in <p:inplace>

i'm using primefaces <p:inplace /> and <p:editor /> to simulate inline editing in my project.
the problem is that when i'm finished editing the inplace shows me html code as a result.
Image of the probleme :
what i want is some thing like this <h:outputtext escape="false"> but in <p:inplace/>
when i searched i found something about averriding the InplaceRendered and i'm beginner and i really don't know how to do that.
can anyone explane to me how to?
thinks.
Editing the PrimeFaces code would be the last option to take.
There was already a similar issue, take a look at this page:
PrimeFaces - Issue 4330
The solution for you could be something like:
<p:inplace editor="true">
<f:facet name="output">
<h:outputText value="#{yourBean.text}" escape="false" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{yourBean.text}" />
</f:facet>
</p:inplace>

Filter Facet is not working in Richface 4.3x

In the Code below, You can observe two things:
1) Default sorting is getting utilized.
2) Image based custom filter is used.
Problem I am facing : When I click on filter image default sorting is getting triggered.
Need a way by which If I click on filter, default sorting doesn't get triggered. (This was achieved in Richface 3.3 by putting this custom filter in filter facet.)
Any help or hint would be greatly appreciated.
<rich:column sortBy="#{model.modVal}" label="Model Value"
sortable="true" id="modelVal" rendered="#{backingBean.renderMap['modVal']}">
<f:facet name="header">
<h:outputText value="Model Value" />
<h:graphicImage title="Filter"
value="#{backingBean.dataModel.modValFilter }">
<a4j:ajax event="click" render="filterCol"
execute="#form"
listener="#{backingBean.loadModalPanelData('modVal') }"
oncomplete="#{rich:component('filterCol')}.show()">
</a4j:ajax>
</h:graphicImage>
</f:facet>
<h:outputText value="#{model.modeVal}"
title="#{model.modelVal}" />
</rich:column>
Use manual sorting, and place a click-able panel in your header for sorting, and another panel for filtering.
The filter facet has been deprecated in favour of the header facet. So what you used to have in the filter facet, you can place in the header facet:
<f:facet name="header">
<h:panelGrid>
<h:outputText value="Model Value"/>
<h:graphicImage title="Model Filter"/>
</h:panelGrid>
</f:facet>

double reference in EL expression

I'm trying to make a "rich:dataTable" with a dynamic number of columns. I have a bean with a List of columns (with attributes headerName and fieldName) and a list of items to be represented in the table so I have next code:
<rich:dataTable id="data_table" value="#{bean.list}" var="item">
<c:forEach items="#{bean.columnList}" var="col">
<rich:column>
<f:facet name="header">
<h:outputText value="#{col['headerName']}" />
</f:facet>
<h:outputText value="??" />
</rich:column>
</c:forEach>
</rich:dataTable>
The problem is that I don't know how to put the value="??" to represent what I want. I want something like:
value="#{item.#{col.fieldName}}"
but I don't know how can I represent it with the correct Expression Language.
I'm using JSF2.1 and Richfaces 4.3.2
Con somebody help me with this issue?
Use the brace notation #{bean[property]}. It allows you to use variables instead of constants as property names.
value="#{item[col.fieldName]}"

Create table columns dynamically in JSF

I'm working on dashboard application where I have to retrieve a set of records and display in dynamic tables boxes. Page frame length is fixed. now of columns and rows can be initialized. It should look like this sample:
Currently I'm using data table to display but it prints all the data in one column. How would I change my code to above pattern?
<o:dataTable id="tabBlSearch" var="item"
onkeyup="handleLeftRightArrowOnDataTable('frmDashBoard:tabBlSearch')"
value="#{bLDashBoardAction.listBondLoc}">
<o:column style="width: 20px;">
<h:outputText value="#{item.awb}" />
</o:column>
</o:dataTable>
You can achieve this with standard JSF components using a <h:panelGrid> wherein <c:forEach> is been used to generate the cells during the view build time. The <ui:repeat> won't work as that runs during view render time.
<h:panelGrid columns="5">
<c:forEach items="#{bean.items}" var="item">
<h:panelGroup>
<h:outputText value="#{item.value}" />
</h:panelGroup>
</c:forEach>
</h:panelGrid>
As to component libraries, I don't see anything in OpenFaces' showcase, but PrimeFaces has a <p:dataGrid> for exactly this purpose, even with pagination support.
<p:dataGrid columns="5" value="#{bean.items}" var="item">
<p:column>
<h:outputText value="#{item.value}" />
</p:column>
</p:dataGrid>

Resources